-1

当我单击在文本标签中设置文本值的记录并且传递的值为空时,我的应用程序崩溃。

- (void) tableView: (UITableView *)itemTableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{
    NSDictionary *obj = [self.dataCustomerDetailRows objectAtIndex:indexPath.row];
    self.textfieldCustomerName.text = [obj objectForKey:@"Name"];
    self.textfieldCustomerPhoneNumber.text = [obj objectForKey:@"Phone"];
    self.textfieldCounty.text = [obj objectForKey:@"Name"];

导致错误的记录是在“电话”obj 中没有返回值的记录,我该如何编写代码来处理这个问题,例如,如果值为 NULL,则替换为 0。

4

1 回答 1

1
NSString *text = [obj objectForKey:@"Property"] == nil ? @"0" : [obj objectForKey:@"Property"];
于 2013-09-13T23:51:38.657 回答