简体   繁体   English

从CoreData获取NSSet并将其显示在Label中

[英]fetch an NSSet from CoreData and show it in a Label

i have an nsset of room attributes(NSString), i stored them in CoreData. 我有一个房间属性(NSString)的nsset,我将它们存储在CoreData中。 how can i fetch them to show it in a UILabel? 如何获取它们以在UILabel中显示?

i tried this in viewDidLoad: 我在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: 当前Raum的声明:

 self.currentRaum = [self.fetchedResultsController objectAtIndexPath:indexPath];

i expected 3 different NSStrings which are saved like this: 我期望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";

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... 编辑答案时看不到问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM