iphonexcodeios6textviewmultiple-results

TextView with multiple result


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 !


Solution

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