TextView有多个结果

时间:2013-02-10 17:04:43

标签: iphone xcode ios6 textview multiple-results

我有类似的东西:

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中列出所有结果,这段代码只显示了最后的结果

寻求帮助!

2 个答案:

答案 0 :(得分:0)

问题出现在你的循环结束时:

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

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

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

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

答案 1 :(得分: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;

我希望这会有用。