-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.namenotificationEntity.describeStringがnullです。tabelviewセルでnotificationEntityのすべての値がnullである理由がわかりません。

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 に答える