i have an nsset of room attributes(NSString), i stored them in CoreData. how can i fetch them to show it in a UILabel?
i tried this in viewDidLoad:
NSArray *array = [[currentRaum raumattribute] allObjects];
[roomAttributLabel setText:[NSString stringWithFormat:@"%@",array]];
but it didn't work. it shows some core data code Screenshot
this is how i save my content:
Raum *raum2 = [NSEntityDescription insertNewObjectForEntityForName:@"Raum" inManagedObjectContext:context];
raum2.raumName = @"Main";
raum2.ort = @"Aschaffenburg";
raum2.strasse = @"Bruchtannenstr. 11";
raum2.etage = @"2. Stock, Raum 1.203";
raum2.beschreibung = @"Gut beleuchtet";
UIImage *img2 = [UIImage imageNamed:@"Main.jpg"];
NSData *data2 = UIImagePNGRepresentation(img2);
raum2.foto = data2;
NSSet *attributeFurRaum2 = [NSSet setWithObjects:attribute4,attribute5,attribute6,nil];
raum2.raumattribute= attributeFurRaum2;
Declaration of currentRaum:
self.currentRaum = [self.fetchedResultsController objectAtIndexPath:indexPath];
i expected 3 different NSStrings which are saved like this:
Raumattribute *attribute4 =[NSEntityDescription insertNewObjectForEntityForName:@"Raumattribute" inManagedObjectContext:context];
attribute4.attributname = @"Copyboard";
Raumattribute *attribute5 =[NSEntityDescription insertNewObjectForEntityForName:@"Raumattribute" inManagedObjectContext:context];
attribute5.attributname = @"Flipchart";
Raumattribute *attribute6 =[NSEntityDescription insertNewObjectForEntityForName:@"Raumattribute" inManagedObjectContext:context];
attribute6.attributname = @"Internetmöglichkeit";
You're going to have to iterate through the array elements to add them to your string. Depending on how you want the string to look, it might be something like:
NSString *compositeString = [ [ NSString alloc ] init ];
for( RaumAttribute *attr in array )
compositeString = [ NSString stringWithFormat:@"%@ %@", compositeString, RaumAttribute.attributeName ];
[roomAttributLabel setText:compositeString];
if I have the field name right. I can't see the question while editing the answer...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.