Reputation: 125
I have a dictionary, in this dictionary, i have arrays. in these arrays, i have views which consist of subviews. One of these subview is a uilabel, i need to reach that uilabel.
When i try to iterate over it, i take an error "collection expression type uiview may not respond to countbyenumaretingwithstate:objects:count"
my code is as below;
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]])
{
}
}
}
}
Upvotes: 0
Views: 175
Reputation: 736
// if a view is having more sub view(i.e., UILable, imageview, UIButton..etc), Now how to identify a particular view.. Below Code is the best example..
// This is a general example, this will help full for all users
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
}
}
Upvotes: 0
Reputation: 1481
I think that you missing this (UIView*)temp.subviews
, in the third for:
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]])
{
}
}
}
}
Upvotes: 3
Reputation: 2819
You could do the following....
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);
}
}];
}];
Upvotes: 1