我觉得空值不太可能是问题(因为你可以anil的text属性UILabel来删除文本)。我怀疑问题是:
我想知道是否[dict objectForKey:@"location"]可以返回字符串以外的其他内容,例如NSDictionary? 我会要么NSLog这个值(或者放一个断点并在那里检查这个值)并确认。或者NSAssert像我下面这样。
不太可能,但我想知道带有标签的子视图103是否真的是一个UILabel?我可能会检查location调试器中的对象以确保。但是如果带有标签的视图103不是 a 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;