[英]fetch an NSSet from CoreData and show it in a Label
我有一个房间属性(NSString)的nsset,我将它们存储在CoreData中。 如何获取它们以在UILabel中显示?
我在viewDidLoad中尝试过这个:
NSArray *array = [[currentRaum raumattribute] allObjects];
[roomAttributLabel setText:[NSString stringWithFormat:@"%@",array]];
但这没用。 它显示了一些核心数据代码截图
这是我保存内容的方式:
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;
当前Raum的声明:
self.currentRaum = [self.fetchedResultsController objectAtIndexPath:indexPath];
我期望3个不同的NSStrings像这样保存:
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";
您将不得不遍历数组元素以将它们添加到字符串中。 根据您希望字符串的外观,它可能类似于:
NSString *compositeString = [ [ NSString alloc ] init ];
for( RaumAttribute *attr in array )
compositeString = [ NSString stringWithFormat:@"%@ %@", compositeString, RaumAttribute.attributeName ];
[roomAttributLabel setText:compositeString];
如果我的字段名称正确。 编辑答案时看不到问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.