我正在尝试使用以下代码加载 UIButton 和 UITextField 以及基于 UISegmentedControl 的当前段的信息,该段被单击但它导致 SIGABRT 崩溃。这是代码:
- (void)updateInfo {
NSLog(@"count1:%d", [self.accounts count]);
[self saveInfo];
NSLog(@"count2:%d", [self.accounts count]);
NSDictionary *dict = [self.accounts objectAtIndex:0];
NSData *imageData = [dict objectForKey:@"ProfileImage"];
UIImage *imageProfile = [UIImage imageWithData:imageData];
[image1 setImage:imageProfile];
NSDictionary *dict2 = [self.accounts objectAtIndex:1];
NSData *imageData2 = [dict2 objectForKey:@"ProfileImage"];
UIImage *imageProfile2 = [UIImage imageWithData:imageData2];
[image2 setImage:imageProfile2];
if ([self.accounts objectAtIndex:accountSC.selectedSegmentIndex] != nil) {
NSDictionary *dict = [self.accounts objectAtIndex:accountSC.selectedSegmentIndex];
//NSString *name = [dict objectForKey:@"Name"];
NSString *name = [accountSC titleForSegmentAtIndex:accountSC.selectedSegmentIndex];
[Name setText:name];
NSData *imageData = [dict objectForKey:@"ProfileImage"];
UIImage *imageProfile = [UIImage imageWithData:imageData];
[pictureButton setImage:imageProfile forState:UIControlStateNormal];
}
else {
Name.text = nil;
[pictureButton setImage:nil forState:UIControlStateNormal];
}
}
第一个和第二个大代码块是临时的,因为我想查看基于不同 objectAtIndex 数字的 UIImage。
这是控制台崩溃日志:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x2cc08'
为什么会发生这种情况?我需要发布我正在使用的任何其他代码吗?
我真的需要帮助,我一直在拔头发!!!
Edit1:我正在使用此代码,您也在谈论 isKindOfClass 对吗?无论如何,这是代码:
NSDictionary *dict = [self.accounts objectAtIndex:1];
if ([dict isKindOfClass:[NSDictionary class]]) {
NSLog(@"YES");
}
else {
NSLog(@"NO");
}
我现在测试...