1

我正在开发一个推特应用程序并尝试实现推文位置。我想要的只是显示国家名称,如果推文有位置,则将其显示在地图上。但是无论我尝试过什么,它总是显示第一条推文的国家,或者如果它为空,应用程序就会崩溃。我不明白我做错了什么。任何人都可以帮忙吗?谢谢!这是我的代码:

   // 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>
4

1 回答 1

0

why do you check value for @"place.name" and then use @"place.full_name"? maybe this is the problem.

and I think you have to check @"geo.coordinates" value before using it.

try to change if statement to if(str && str.lengh)

and change NSString *str = [dic valueForKeyPath:@"place.name"]; to NSString *str = [[dic valueForKeyPath:@"place.name"] lastObject]; because valueForKeyPath returns an array.

于 2013-08-19T21:24:03.930 回答