0

我有一本字典,在这本字典中,我有数组。在这些数组中,我有由子视图组成的视图。这些子视图之一是 uilabel,我需要到达该 uilabel。

当我尝试对其进行迭代时,出现错误“集合表达式类型 uiview 可能无法响应 countbyenumaretingwithstate:objects:count”

我的代码如下;

for(int i = 0; i<counterRow;i++)
{
    NSString *dictTempKey = [NSString stringWithFormat:@"row%d",i];

  NSMutableArray * tempArray =  [doctorAddition objectForKey:dictTempKey];

    for(UIView * subview in tempArray)
    {

        UIView * temp = subview;

        for(UIView * subview2 in (UIView*)temp)
        {
            if([subview2 isKindOfClass:[UILabel class]])
            {

            }

        }

    }

}
4

3 回答 3

3

我认为你(UIView*)temp.subviews在第三个中错过了这个:

for(int i = 0; i<counterRow;i++)
{
    NSString *dictTempKey = [NSString stringWithFormat:@"row%d",i];

  NSMutableArray * tempArray =  [doctorAddition objectForKey:dictTempKey];

    for(UIView * subview in tempArray)
    {

        UIView * temp = subview;

        for(UIView * subview2 in (UIView*)temp.subviews)
        {
            if([subview2 isKindOfClass:[UILabel class]])
            {

            }

        }

    }

}
于 2013-08-13T06:35:56.667 回答
1

您可以执行以下操作....

NSArray *values = [doctorAddition allValues];

[values enumerateObjectsUsingBlock:^(UIView *aView, NSUInteger index, BOOL *stop) {

    [aView.subviews enumerateObjectsUsingBlock:^(id aSubView, NSUInteger index, BOOL *stop) {

        if ([aSubView isKindOfClass:[UILabel class]]) {
            NSLog(@"Found UILabel: %@", aSubView);
        }
    }];
}];
于 2013-08-13T06:35:31.823 回答
0

// 如果一个视图有更多的子视图(即,UILable、imageview、UIButton..etc),现在如何识别一个特定的视图.. 下面的代码是最好的例子..

// 这是一个通用示例,这将有助于所有用户

for (UIView *subview_obj in [View_obj subviews])// Here it ll fetch all subview from view
{
   if ([subview_obj isKindOfClass:[UIButton class]])// here it ll identify perticular view from all subview
   {
     // Do Something
   }
}
于 2013-08-13T06:45:20.057 回答