我正在创建这个应用程序,但是当 NSDictionary 中的给定条目没有值时,我不知道如何处理该错误。这是我目前拥有的代码:
NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];
NSString *user = entry[@"user"][@"full_name"];
NSString *caption = text[@"caption"][@"text"];
if (caption != nil && entry != [NSNull null] && text != nil && caption != [NSNull null]) {
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self title:user message:caption];
[modal show];
}
这是我在没有任何标题的情况下点击单元格时收到的错误响应:
2013-08-08 02:36:57.871 Floadt[5566:c07] -[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x310b678
2013-08-08 02:36:57.872 Floadt[5566:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x310b678'
*** First throw call stack:
(0x2fda012 0x260be7e 0x30654bd 0x2fc9bbc 0x2fc994e 0x5606b 0x1c7a42f 0x1c8c182 0x1c8c394 0x261f705 0x188693c 0x18869ac 0x261f705 0x188693c 0x18869ac 0x1a401d3 0x2fa2afe 0x2fa2a3d 0x2f807c2 0x2f7ff44 0x2f7fe1b 0x2bb77e3 0x2bb7668 0x1778ffc 0x2d2d 0x2c55)
libc++abi.dylib: terminate called throwing an exception