【问题标题】:TextView with multiple result具有多个结果的 TextView
【发布时间】:2013-01-25 20:24:54
【问题描述】:

我有类似的东西:

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

谢谢帮助!

【问题讨论】:

    标签: iphone xcode ios6 textview multiple-results


    【解决方案1】:

    问题出现在循环的末尾:

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

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

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

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

    【讨论】:

    • 如果这是您问题的答案,请将其标记为正确答案。谢谢
    【解决方案2】:

    您每次都在重新设置 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;
    

    我希望这会有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多