-1

当我进入 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 都是空的。我不知道为什么在 tabelview 单元格中 notificationEntity 的所有值都是空的。

4

1 回答 1

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);
于 2012-11-03T08:39:56.947 回答