UITableView只显示一个单元格?

时间:2014-08-19 21:30:38

标签: ios objective-c uitableview jailbreak

所以,我正在编写一个越狱调整,它使用UITableView。我的班级AscendCustomTableCell刚刚为视图添加内容的方法。

所以,问题是表视图只显示最新的通知。例如,如果我得到一个文本,它工作正常,但如果我得到另一个文本,第一个文本消失,第二个文本进入表视图的第二个单元格。

每次收到通知时,我都会将其添加到通知数组中,然后重新加载表格视图。老电池为什么不留下来?

代码:

@interface AscendTableViewDelegate : NSObject <UITableViewDelegate, UITableViewDataSource>

@end

@implementation AscendTableViewDelegate

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

    //[cell grabFromBBBulletin:[activeLockScreenNotifications objectAtIndex:indexPath]];
    AscendCustomTableCell *cell = [ascendNotificationTable dequeueReusableCellWithIdentifier:@"notifTableCell"];
        [cell grabFromBBBulletin:[activeLockScreenNotifications objectAtIndex:indexPath.row]]; 
    if (cell == nil) {
        cell = [[AscendCustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"notifTableCell"];
    }
    //[cell trashOldLabels];
    cell.separatorInset = UIEdgeInsetsZero;

    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return [activeLockScreenNotifications count];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  return 85;
}

@end

1 个答案:

答案 0 :(得分:0)

可能发生的事情是旧单元指向的数据源可能正在被释放。因此,当您重新加载表时,旧单元格将使用指向已释放对象的指针进行更新。当有新通知进入时,您需要将内容复制到您自己的数据源(对象数组)。只需在您的类上创建NSMutableArray属性或ivar并复制数据,然后使用您自己的数据源重新加载表视图。

相关问题