相关疑难解决方法(0)

dequeueReusableCellWithIdentifier永远不会返回nil

我在我的UITableView中使用自定义UITableViewCell,但问题是当调用dequeueReusableCellWithIdentifier时,单元格永远不会为nil.为什么是这样 ?

- (void)viewDidLoad
{
    [super viewDidLoad];
    UINib *nib = [UINib nibWithNibName:@"PHResultTableViewCell" bundle: nil];
    [[self tableView] registerNib:nib forCellReuseIdentifier:@"MyCell"];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    PHResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
    if (cell == nil)
    {
        PackageHolidayItem *obj=[[PackageHolidayItem alloc]init];
        obj= [totalArray objectAtIndex:indexPath.row];
        cell.packageHolidayItem = obj;
        [cell loadRow];

    }
    return cell;
}    
Run Code Online (Sandbox Code Playgroud)

uitableview ios

20
推荐指数
3
解决办法
5960
查看次数

标签 统计

ios ×1

uitableview ×1