Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 对象属性不会加载到cellForRowAtIndexPath中_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 对象属性不会加载到cellForRowAtIndexPath中

Ios 对象属性不会加载到cellForRowAtIndexPath中,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有一个UITableViewController,它使用AFNetworking从数据源加载单元格。数据是异步加载的,所以我设置了notif,以便在加载新数据时更新我的tableView。每次新数据到达并更新我的对象属性时,都会调用reloadTable,但这些属性不会加载到我的cellForRowAtIndexPath中 在重新加载表中记录属性时,它们是正确的。但是在我的手机里说空是因为它的路径 这是我的密码 这将创建一个对象“移位”并开始加载数据,然后在加载新数据并更新表时接收notif

我有一个UITableViewController,它使用AFNetworking从数据源加载单元格。数据是异步加载的,所以我设置了notif,以便在加载新数据时更新我的tableView。每次新数据到达并更新我的对象属性时,都会调用reloadTable,但这些属性不会加载到我的cellForRowAtIndexPath中

在重新加载表中记录属性时,它们是正确的。但是在我的手机里说空是因为它的路径

这是我的密码

这将创建一个对象“移位”并开始加载数据,然后在加载新数据并更新表时接收notif

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行打招呼。

我想是因为您混合了ivar\u移位和属性self.shifts。如果使用旧版本的Xcode,则必须使用以下代码@synthesis实现部分中的属性:

@synthesize shifts = _shifts;
@property (nonatomic, retain)  <YourObjectClass>* shifts;
如果使用最新版本的Xcode,则无需声明ivar\u移位变量,只需使用以下代码声明属性:

@synthesize shifts = _shifts;
@property (nonatomic, retain)  <YourObjectClass>* shifts;

在代码的所有位置都必须使用self.shifts属性,而不是ivar变量_shifts

您从未分配并初始化变量“cell”,检查代码,变量“cell”仍然是nul。

确保在模型对象中使用强而不是弱声明属性。没有看到你的代码,我猜这是最有可能的问题。在某些情况下,您确实希望在视图控制器中使用弱(例如:IBOutlets),但在拥有其数据的数据对象的情况下则不使用弱(例如:IBOutlets)。

为什么不显示存储数据的位置/方式?在我看来,这就是问题所在。@NicholasHart为什么我的数据加载并显示在我的重新加载数据函数中,而不是CellForRowatineXpath:?我会用我的数据更新我的问题好的,我不太明白你是如何存储数据的。你能给我看一下剪辑的声明吗?看起来它正在丢失数据。也许你的财产很弱,而不是很强。@NicholasHart BOOM!你搞定了,谢谢。。为什么我要把弱属性??哑的做出回答,我会把它排除在外。谢谢如果您询问属性,为什么不向我们展示属性声明?在代码的所有位置都必须使用self.shifts属性,而不是ivar变量_shifts。这是不必要的。为什么他必须使用该属性?如果您在没有保留的情况下使用ivar,您可能会发生一些崩溃,使用该属性,机制保留释放是肯定的。苹果公司建议仅在评估员覆盖中使用ivar,但不禁止使用ITE解释什么是MRC?好的,我的样本当然在MRC中,在这种情况下是正确的。您很苛刻他使用的是iOS 6,而不是dequeueReusableCellWithIdentifier:。如果故事板设置正确且单元类已注册,则他不得处理单元创建。顺便说一句:阅读问题下方的注释-此问题已解决。