我有一个 UITableViewController,它使用 AFNetworking 从数据源加载单元格。数据加载异步,因此我设置了一个通知以在加载新数据时更新我的 tableView。每次新数据到达并更新我的对象属性时都会调用 reloadTable,但这些属性不会加载到我的 cellForRowAtIndexPath 中。
当我在重新加载表中 NSLog 我的属性时,它们是正确的。但是在我的 cellForRowAtIndexPath 中说 null
这是我的代码...
这将创建一个对象“shifts”并开始加载数据,然后在加载新数据并更新表时收到通知
NSDictionary *params = @{@"game_id":self.gameID, @"player_id":_sharedPlayer.playerID, @"category_id":self.categoryID};
_shifts = [[ClipShiftController alloc] init];
[_shifts fetchShifts:params];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable:)
name:@"clipLoaded"
object:nil];
这是我的重载表:
- (void)reloadTable:(NSNotification *)notif
{
[self.tableView reloadData];
Clip *clip = [self.shifts.shiftDataSet objectAtIndex:i];
NSLog(@"clip counter %i",[self.shifts.shiftDataSet count]);
NSLog(@"clip name %@",clip.name);
i++;
}
这是 cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Clip *clip = [_shifts.shiftDataSet objectAtIndex:indexPath.row];
NSLog(@"CELL COUNTER %i",[_shifts.shiftDataSet count]);
NSLog(@"CLIP CELL name %@",clip.name);
NSLog(@"row called");
cell.textLabel.text = @"hello";
//This is null cell.textLabel.text = clip.name;
return cell;
}
这是我的控制台输出
2013-08-26 12:16:50.831 One Six[15632:c07] clip counter 1
2013-08-26 12:16:50.831 One Six[15632:c07] clip name shift
2013-08-26 12:16:50.831 One Six[15632:c07] clip counter 2
2013-08-26 12:16:50.832 One Six[15632:c07] clip name shift
2013-08-26 12:16:50.832 One Six[15632:c07] clip counter 3
2013-08-26 12:16:50.832 One Six[15632:c07] clip name shift
2013-08-26 12:16:50.832 One Six[15632:c07] clip counter 4
2013-08-26 12:16:50.833 One Six[15632:c07] clip name shift
2013-08-26 12:16:50.833 One Six[15632:c07] clip counter 5
2013-08-26 12:16:50.833 One Six[15632:c07] clip name face off
2013-08-26 12:16:50.833 One Six[15632:c07] clip counter 6
2013-08-26 12:16:50.833 One Six[15632:c07] clip name face off
2013-08-26 12:16:50.834 One Six[15632:c07] clip counter 7
2013-08-26 12:16:50.834 One Six[15632:c07] clip name face off
2013-08-26 12:16:50.834 One Six[15632:c07] clip counter 8
2013-08-26 12:16:50.835 One Six[15632:c07] clip name shift
2013-08-26 12:16:50.835 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.835 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.836 One Six[15632:c07] row called
2013-08-26 12:16:50.836 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.836 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.837 One Six[15632:c07] row called
2013-08-26 12:16:50.838 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.838 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.838 One Six[15632:c07] row called
2013-08-26 12:16:50.839 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.839 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.839 One Six[15632:c07] row called
2013-08-26 12:16:50.840 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.840 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.841 One Six[15632:c07] row called
2013-08-26 12:16:50.841 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.841 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.842 One Six[15632:c07] row called
2013-08-26 12:16:50.842 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.844 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.844 One Six[15632:c07] row called
2013-08-26 12:16:50.845 One Six[15632:c07] CELL COUNTER 8
2013-08-26 12:16:50.845 One Six[15632:c07] CLIP CELL name (null)
2013-08-26 12:16:50.846 One Six[15632:c07] row called
显示的是我的表格视图中的 8 行打招呼。