2009-11-26 22 views
1

如何打印實體的內容顧客?核心數據:打印實體的內容

我希望數據能夠像表格一樣,例如實體數據應如此打印:

名稱|姓氏|電話號碼|電子郵件| DOB

我還需要在打印數據之前應用搜索謂詞,例如,打印成員1984年後出生

有人能告訴我應該怎麼做嗎?

謝謝!

回答

4

我發現這個鏈接,幫助了我很多使用核心數據: http://iphoneinaction.manning.com/iphone_in_action/2009/09/core-data-part-3-retrieving-data.html

演員實體到一個數組,循環數組和NSLog的每個結果的數據。例如:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"news" 
              inManagedObjectContext:self.managedObjectContext]; 
[fetchRequest setEntity:entity]; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"url=%@",theUrl]; 
[fetchRequest setPredicate:predicate]; 

NSError *error; 
NSArray *items = [self.managedObjectContext 
        executeFetchRequest:fetchRequest error:&error]; 

for (news *theNews in items) { 
    NSLog(@"Title: %@, Date: %@, News: %@", [theNews title], [theNews date], [theNews news]); 
} 

[fetchRequest release]; 
+0

謝謝!這個資源真的有幫助! – Michael 2009-11-30 22:44:45