Question

How do i display all data in a UILabel?

I am currently using this :

    for (NSManagedObject *obj in matchingData)
    {
        lastname = [obj valueForKey:@"lastname"];
        name = [obj valueForKey:@"name"];

        NSLog(@"Name:%@\n Last Name %@\n", [obj valueForKey:@"name"],[obj valueForKey:@"lastname"]);
    }

    self.displayLabel2.text = [NSString stringWithFormat:@"Guest : %@  %@" ,name, lastname];
}

In the console I get all my data but in UILabel (displayLabel2) I just get one name…i just don't get it…

Était-ce utile?

La solution

The way that your code reads, on each loop through the obj NSManagedObject, the name and lastname will be reset. So the label will only display the final loop's data.

try creating a string within the loop

NSMutableString *stringText = [NSMutableString string];

for (NSManagedObject *obj in matchingData)

{
    lastname = [obj valueForKey:@"lastname"];
    name = [obj valueForKey:@"name"];

    NSLog(@"Name:%@\n Last Name %@\n", [obj valueForKey:@"name"],[obj valueForKey:@"lastname"]);
    stringText = [NSString stringWithFormat:@"%@ %@", stringText, [NSString stringWithFormat:@"Guest : %@  %@" ,name, lastname]];

}

self.displayLabel2.text = stringText;

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top