How do you load custom UITableViewCells from Xib files?

前端 未结 23 1998
抹茶落季
抹茶落季 2020-11-22 11:11

The question is simple: How do you load custom UITableViewCell from Xib files? Doing so allows you to use Interface Builder to design your cells. The answer app

23条回答
  •  深忆病人
    2020-11-22 11:41

    The right solution is this:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        UINib *nib = [UINib nibWithNibName:@"ItemCell" bundle:nil];
        [[self tableView] registerNib:nib forCellReuseIdentifier:@"ItemCell"];
    }
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Create an instance of ItemCell
        PointsItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemCell"];
    
        return cell;
    }
    

提交回复
热议问题