2013-03-30 31 views
0

我有这样的代码:向下滚动崩溃应用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"BSTGListCell"; 

    BSTGListCell *cell = (BSTGListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[NSBundle mainBundle] loadNibNamed:@"BSTGListCell" owner:self options:nil] objectAtIndex:0]; 
    } 

    PFObject* currentEl = [self.tableData objectAtIndex:indexPath.row]; 

    cell.title.text = [currentEl objectForKey:@"Name"]; 
    cell.description.text = [currentEl objectForKey:@"Address"]; 
    return cell; 
} 

我收到“消息发送到释放实例”向下滚动其添加为表视图时一个子视图。 僵尸检查员说,访问对象在这里保留:

cell = [[[NSBundle mainBundle] loadNibNamed:@"BSTGListCell" owner:self options:nil] objectAtIndex:0]; 

,并可能是由ARC释放。 为什么会发生这种情况,我如何防止它?

回答

1

你真的不应该这样做。使用细胞从笔尖的方法是注册笔尖,可能是在viewDidLoad中,像这样的:

UINib *nib = [UINib nibWithNibName:@"BSTGListCell" bundle:nil]; 
[self.tableView registerNib:nib forCellReuseIdentifier:@"BSTGListCell"]; 

然后在你的cellForRowAtIndexPath,使用dequeueReusableCellWithIdentifier:forIndexPath:没有如果(细胞==零)条款。

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

    BSTGListCell *cell = (BSTGListCell *)[tableView dequeueReusableCellWithIdentifier:@"BSTGListCell" forIndexPath:indexPath]; 

    PFObject* currentEl = [self.tableData objectAtIndex:indexPath.row]; 

    cell.title.text = [currentEl objectForKey:@"Name"]; 
    cell.description.text = [currentEl objectForKey:@"Address"]; 
    return cell; 
} 

与您的代码的实际问题是,loadNibNamed:业主:选项,返回一个数组,你必须得到一个对象的是数组,你把它分配给小区之前。但是,我展示的方式无论如何都是更有效的方法。

+0

这不完全是我用了修复,但非常接近的。 – Octavian

+0

@Octavian,你使用了什么修补程序? – rdelmar

+0

请为面临同样问题的其他人添加您的解决方案! – cph2117