Note that there are some explanatory texts on larger screens.

plurals
  1. POCan not load core data in a table view?
    primarykey
    data
    text
    <p>I am doing a Karaoke project. I want to load my data to a table view using NSManagedObjectModel but It didnt work</p> <p>Firstly, I load all songs in my KBDataInitializer.m and it work fine. I can push them to an array. I also can NSlog all songs name.</p> <pre><code>@implementation KBDataInitializer - (NSArray*) getAllSongs{ [self setupDataContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc ] initWithEntityName:@"KBSong"]; NSError *fetchError; NSArray *songs = [self.dataContext executeFetchRequest:fetchRequest error:&amp;fetchError]; if (fetchError !=NULL){ NSLog(@"fetch data ERROR"); } return songs; } </code></pre> <p>BUT when I load each song to the tableview in my HomeController it display nothing and when I try to NSlog my variable *song it show an message (which mean they can not load data):</p> <pre><code>$3 = 0x0e483d90 &lt;KBSong: 0xe483d90&gt; (entity: KBSong; id: 0x818b630 &lt;x-coredata://4BA983BA-1914-47C9-A22B-0373E84EAFC8/KBSong/p1&gt; ; data: &lt;fault&gt;) However in my viewDidLoad() I can load all songs. </code></pre> <p>My code in HomeController.h</p> <pre><code>@interface KBHomeController : UIViewController&lt;UITableViewDataSource,UITableViewDelegate&gt; { NSArray *songs; } @end </code></pre> <p>This is my loading code in my table view in HomeController.m</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. KBDataInitializer *data = [[KBDataInitializer alloc]init]; //Use for import updated new Songs //[data importData]; songs = [data getAllSongs]; // This one works fine for (KBSong *song in songs) { NSLog(song.name); } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableItem"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } KBSong *song = [songs objectAtIndex:indexPath.row]; cell.textLabel.text = song.name; return cell; } </code></pre> <p>This is my KBSong.h</p> <pre><code>@interface KBSong : NSManagedObject @property (nonatomic, retain) NSNumber * code; @property (nonatomic, retain) NSString * composer; @property (nonatomic, retain) NSString * language; @property (nonatomic, retain) NSString * lyric; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSNumber * volume; @property (nonatomic, retain) NSNumber * favorite; @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload