如何获取子视图中添加的值
如何获取添加到 UIView 的子视图的值。
我在子视图中添加了五个按钮。
现在我需要从子视图中获取第二个、第三个、第四个。
for(id btn in [myview subviews]){
.... which prints all the elements added in view.
}
如何将特定元素添加到子视图中。
@提前致谢
How to get the value of subviews which added to UIView.
I Have added five button to the subviews.
Now i need to get 2nd 3rd 4th from the subviews.
for(id btn in [myview subviews]){
.... which prints all the elements added in view.
}
how to get specific elements added to subviews.
@thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确的话,
[[myview subviews] objectAtIndex:2]
。依赖子视图中项目的顺序是安全的*ish*。尽管它们可以作为其他操作的副作用进行重新排列。您最好使用数据成员或分配
标签
。If I understand you right,
[[myview subviews] objectAtIndex:2]
.It’s safe*ish* to rely on the order of items in subviews. Though they can be rearranged as side effects of other operations. You’d be better off using data members or assigning a
tag
.创建按钮时存储指向按钮的指针,或者为每个按钮分配唯一的标签值并通过其标签获取按钮。
Either store pointers to the buttons when you create them, or assign unique tag values to each button and fetch the buttons by their tags.