0

我有类似的东西:

for(MKMapItem *mapItem in response.mapItems){
        MKPlacemark *placeMark = mapItem.placemark;
        NSLog(@"showSearchResponse: mapItem = %@ coordinate = %g,%g \nname = %@\naddressDictionary = %@",
              mapItem,
              placeMark.coordinate.latitude,
              placeMark.coordinate.longitude,
              mapItem.name,
              placeMark.addressDictionary);

        [self.mapView addAnnotation:placeMark];

        scrollText.editable=NO;
        scrollText.scrollEnabled = YES;
        scrollText.text = [NSString stringWithFormat:@"%@",placeMark.addressDictionary];

我想在 TextView 中列出所有结果,这段代码只显示了最后一个结果

谢谢帮助!

4

2 回答 2

0

问题出在循环的末尾:

scrollText.text = [NSString stringWithFormat:@"%@",placeMark.addressDictionary];

您正在将文本重置为最后一个条目。

所以你有两个选择。其中一次只是将一个字符串与您的结果连接起来,并将其设置为您的 scrollText 的文本,或者像这样在 scrollText 上连接字符串

scrollText.text = [NSString stringWithFormat:@"%@%@",scrollText.text, placeMark.addressDictionary];
于 2013-02-10T17:08:20.563 回答
0

您每次都在重新设置 scrollText 的值。所以试试这个:

NSMutableString *resultString = [[NSMutableString alloc]init];

for(MKMapItem *mapItem in response.mapItems){
        MKPlacemark *placeMark = mapItem.placemark;
        NSLog(@"showSearchResponse: mapItem = %@ coordinate = %g,%g \nname = %@\naddressDictionary = %@",
              mapItem,
              placeMark.coordinate.latitude,
              placeMark.coordinate.longitude,
              mapItem.name,
              placeMark.addressDictionary);

        [self.mapView addAnnotation:placeMark];


        [resultString appendFormate:@"%@\n",placeMark.addressDictionary];

}

scrollText.editable=NO;
scrollText.scrollEnabled = YES;
scrollText.text = resultString;

我希望这会有用。

于 2013-02-10T17:18:55.477 回答