iphone - 遍历 View : Objective-c 中的特定类

标签 iphone objective-c ios xcode

我一直在使用以下代码循环访问我的 subview 中的特定类。

  for (int i = 0; i < [[self.view subviews] count]; i++) {
        if ([[self.view.subviews objectAtIndex:i] class] == [UIButton class]) {

        }
    }

但我觉得应该有更好的方法。有人可以帮帮我吗?

谢谢。

最佳答案

for(UIView *v in [self.view subviews]) {
  if ([v isKindOfClass:[UIButton class]]) {
    ...
  }
}

关于iphone - 遍历 View : Objective-c 中的特定类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7406197/

相关文章:

iphone - 比较两个 NSDate 并忽略时间分量

iOS8.2 不播放来自 parse.com 应用程序的自定义警报声音

ios - Firebase 的 putData (存储)和 setData (数据库)是否会不断尝试直到成功/失败?

iphone - 从 XCode 中的 SQLite 数据库获取一定半径内的所有位置

iphone - 在jQuery .click()的UIWebView App中检查Internet

ios - Swift:IBoutlet 总是返回 nil 对象?

objective-c - insertItemsAtIndexPaths 更新错误

ios - Storyboard - 设置委托(delegate)

ios - 如何在 swift 中将月份名称数组转换为月份编号

objective-c - 使用 uitabbarcontroller 在 iOS 中管理套接字