2013-08-04 36 views
0

我已经设置了MySQL数据库并已解析JSON到我的XCode项目。但是,我在下面的第四行发现了一个THREAD 1: signal SIGABRT错误。我认为这是由于数据库中“位置”变量之一的空值。这是原因吗?如果是这样,我怎样才能让它忽略null的值,只是把标签留空?在此先感谢您的时间。mysql null值抛出xcode错误

UILabel *event = (UILabel *)[cell viewWithTag:102]; 
event.text = [dict objectForKey:@"event"]; 

UILabel *location = (UILabel *)[cell viewWithTag:103]; 
location.text = [dict objectForKey:@"location"]; 

回答

0

我感到那空值是不太可能的问题(因为你可以nil一个UILabeltext属性删除文本)。我怀疑,这个问题可以是:

  1. 不知[dict objectForKey:@"location"]可以返回字符串以外的东西,比如一个NSDictionary?我要么NSLog这个值(或放在一个断点,并检查这个值)并确认。或者像下面这样写入NSAssert

  2. 不太可能,但我不知道子标签103是否真的是UILabel?我可能会检查调试器中的location对象以确定。但是,如果带有103标记的视图不是UILabel,那么您可能会收到错误消息。

因此,也许是这样的:

UILabel *location = (UILabel *)[cell viewWithTag:103]; 
NSAssert([location isKindOfClass:[UILabel class]], @"%s: view with tag 103 is not UILabel: %@", __FUNCTION__, location); 
NSString *locationString = [dict objectForKey:@"location"]; 
NSAssert(locationString == nil || [locationString isKindOfClass:[NSString class]], @"locationString is not nil but not string either: locationString = %@", locationString); 
location.text = locationString; 
+0

嗨,罗布。我试过上面的代码。我一直得到同样的错误。但是,我现在已确认它是导致错误的空值。我在位置变量中输入了一个值,代码运行平稳。任何其他想法?谢谢。 – newman

+0

@newman是'locationString'作为'nil'值还是'[NSNull null]'值返回?当你添加上面的NSAssert值时,是否记录了任何有趣的内容? – Rob