将UISegmentedControl中的段添加到NSArray

时间:2015-05-22 00:29:58

标签: ios objective-c nsarray uisegmentedcontrol for-in-loop

我正在尝试向segments添加2 array,然后循环浏览其子视图。这是我的代码:

NSArray *myArray = [[NSArray alloc] initWithObjects:[self.segment.subviews objectAtIndex:0],
                                   [self.dataSegmentedControl.subviews objectAtIndex:1], nil];


for (id innerView in myArray) // I tried "myArray.subviews" but it didn't let me do ".subviews"
{
    if ([innerView isKindOfClass:[UILabel class]]) {
        ...
    }
}

当我在NSLog中插入if statement时,我没有得到任何输出。我该怎么做才能解决这个问题?:

1 个答案:

答案 0 :(得分:0)

您所看到的只有两个可能的原因:

  1. 阵列的元素都不是UILabel
  2. 数组中没有元素。这可能是因为[self.segment.subviews objectAtIndex:0]返回nil,这只表示self.segment为零。
  3. 在假设之前尝试探索视图层次结构。因此,打印出段及其子视图以了解层次结构。

    但是,如果你想改变某些片段的字体大小而不想改变其他片段的字体大小,我建议不要这样做并且弄乱内部结构。如果它成功了,您应该预计任何即将发布的系统更新都会出现问题。 我建议您搜索其他第三方组件或构建自己的组件。