dequeueReusableCellWithIdentifier never returns nil

前端 未结 4 516
臣服心动
臣服心动 2020-12-06 00:30

I am using a custom UITableViewCell in my UITableView but the problem is that the cell is never nil when calling the dequeueReusableCellWithIdentifier. Why is this ?

4条回答
  •  無奈伤痛
    2020-12-06 00:53

    As others have pointed out if you have registerd a nib to reuse a tableViewCell you are guaranteed to get an instance of cell. If you want to set some value to the cell. You can try modifying your code like this

    - (UITableViewCell *)tableView:(UITableView *)tableView 
             cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
            PHResultTableViewCell *cell = (PHResultTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCell" 
                                                                                                   forIndexPath:indexPath];];
    
            cell.packageHolidayItem = totalArray[indexPath.row];;
            [cell loadRow];
    
            return cell;
        }    
    

提交回复
热议问题