在tableView上没有显示coredate数据

时间:2012-11-03 04:58:17

标签: iphone ios

当我进入viewController:

时,我在tableView上使用了coredate
dispatch_queue_t downloadQueue = dispatch_queue_create("socket login", NULL);
dispatch_async(downloadQueue, ^{
    NSManagedObjectContext *managedObjectContext =[self getManagedObjectContext];
    noticListArr=[[CoreDataManager sharedInstance] readEvent:@"NotificationEntity" SortDescriptor:nil managedObjectContext:managedObjectContext];
    NSLog(@"refreshData.count:%d ",noticListArr.count);
    for(int i=0;i<noticListArr.count;i++){
        NotificationEntity *notificationEntity=[noticListArr objectAtIndex:i];
        NSLog(@"notificationEntity.name:%@ ",notificationEntity.name);
        NSLog(@"notificationEntity.describeString:%@ ",notificationEntity.describeString);
        NSLog(@"notificationEntity.source:%@", notificationEntity.source);
    }     
});

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView1 reloadData];
});
dispatch_release(downloadQueue);

所有日志都包含值,但是当我使用

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     static NSString *CellIdentifier = @"NotificationViewCell";
     NotificationViewCell *cell = (NotificationViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

     NotificationEntity *notificationEntity=(NotificationEntity *)[noticListArr objectAtIndex:indexPath.row];

     NSLog(@"tableViewnoticListArr.count:%d ",noticListArr.count);
     NSLog(@"indexPath.row:%d ",indexPath.row);

     NSLog(@"notificationTable.avatarsmall:%@", notificationEntity.avatarsmall);
     NSLog(@"notificationTable.source:%@", notificationEntity.source);
     NSLog(@"notificationTable.name:%@", notificationEntity.name);
     NSLog(@"notificationTable.describeString:%@ ",notificationEntity.describeString);
 }

 NSLog(@"tableViewnoticListArr.count:%d ",noticListArr.count);
 NSLog(@"indexPath.row:%d ",indexPath.row);

给出了正确的结果,但所有notificationEntity.name notificationEntity.describeString都为null。我不知道为什么在tabelview单元格中,notificationEntity的所有值都为null。

1 个答案:

答案 0 :(得分:0)

检查此更改,

dispatch_async(downloadQueue, ^{
    NSManagedObjectContext *managedObjectContext = [self getManagedObjectContext];
    self.noticListArr = [[CoreDataManager sharedInstance] readEvent:@"NotificationEntity" SortDescriptor:nil managedObjectContext:managedObjectContext];
    NSLog(@"refreshData.count:%d ",noticListArr.count);
    for(int i=0; i<noticListArr.count; i++){
        NotificationEntity *notificationEntity = [noticListArr objectAtIndex:i];
        NSLog(@"notificationEntity.name:%@ ", notificationEntity.name);
        NSLog(@"notificationEntity.describeString:%@ ", notificationEntity.describeString);
        NSLog(@"notificationEntity.source:%@", notificationEntity.source);
    }     
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView1 reloadData];
    });
});

dispatch_release(downloadQueue);