けっこうよく使うメソッドがこれ、isKindOfClass。配列にいろんなクラスをいれていて例えばUIViewのクラスならば、というふうな命令が下せる。
NSMutableArray *anArray = [[NSMutableArray alloc] init];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
[anArray addObject: [NSNumber numberWithInt:284]];
[anArray addObject: aView];
[anArray addObject: [NSString stringWithFormat:@"a string"]];
for (id aObject in anArray){
if([aObject isKindOfClass:[UIView class]]){
NSLog(@"aObject is a UIView: %@", aObject);
}
}
No comments:
Post a Comment