【发布时间】:2013-08-21 18:00:21
【问题描述】:
我正在开发一个推特应用程序并尝试实现推文位置。我想要的只是显示国家名称,如果推文有位置,则将其显示在地图上。但是无论我尝试过什么,它总是显示第一条推文的国家,或者如果它为空,应用程序就会崩溃。我不明白我做错了什么。任何人都可以帮忙吗?谢谢! 这是我的代码:
// LOCATION
for (NSDictionary *dic in self.dataSource)
{
NSString *str = [dic valueForKeyPath:@"place.name"];
if(str)
{
cell.button.hidden = NO;
cell.location.text = [dic valueForKeyPath:@"place.full_name"];
self.coordinates = [dic valueForKeyPath:@"geo.coordinates"];
break;
} else {
cell.button.hidden = YES;
cell.location.hidden = YES;
break;
}
}
这是 NSLog 输出:
2013-08-20 00:04:42.269 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.269 TwitterApplication[10011:c07] Downtown
2013-08-20 00:04:42.269 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.270 TwitterApplication[10011:c07] Moscow
2013-08-20 00:04:42.270 TwitterApplication[10011:c07] Брянск
2013-08-20 00:04:42.270 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.271 TwitterApplication[10011:c07] Брянск
2013-08-20 00:04:42.271 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.271 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.272 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.272 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.272 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.273 TwitterApplication[10011:c07] <null>
2013-08-20 00:04:42.273 TwitterApplication[10011:c07] <null>
【问题讨论】:
-
生成该日志的代码是什么?
-
如果推文有位置,则城市名称,如果没有,则为 null。
-
显示它的代码以及它与您显示的代码的关系。
-
是这样的: for (NSDictionary *dic in self.dataSource) { NSString *str = [dic valueForKeyPath:@"place.name"]; NSLog(@"%@", str);我只是想确保我得到城市名称。
-
正如你所说,这个 str 可能为空。尝试使用 if([str isEqualToString:@""])。
标签: iphone ios twitter nsdictionary