Pregunta

I Have something like that:

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];

i want to list all the results in TextView, this code showed me only last result

Thx for help !

¿Fue útil?

Solución

The problem is at the end of your loop:

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

You are resetting the text to the last entry.

So you have two options. Once of them is just concatenate a string with your results and set that as the text for your scrollText or concatenate the string over scrolText like this

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

Otros consejos

You are re-setting value of scrollText each time. So try this one:

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;

I hope this will be useful.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top