簡體   English   中英

從CoreData獲取NSSet並將其顯示在Label中

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM