I sometimes like to organize IB elements in NSArray , primarily to help me organize my elements. Most often, different classes of objects turn them into the same array with each other. Although this is a convenient way to organize, I can't seem to wrap my head around why, if I have such an array:
NSArray *array = [NSArray arrayWithObjects:((UITextField *)textField), ((UISegmentedController *)segmentedController), nil];
Why do I get the "Doesn't respond to selector" messages when I put a for loop like this:
for (UITextField *text in array) { [text setText:@""]; }
The for loop seems to be passed to objects that are not in the UITextField class.
What is the point of declaring an object class if all the objects in the specified array go through a loop?
EDIT Just for reference, here's how I handle it now:
for (id *object in array) { if ([object isMemberOfClass:[UITextField class]]) { foo(); } else if ([object isMemberOfClass:[UISegmentedController class]) { bar(); } }
esqew
source share