how to create custom tableViewCell from xib

前端 未结 3 692
一生所求
一生所求 2020-12-10 06:31

I want to create a custom TableViewCell on which I want to have UITextField with editing possibility. So I created new class with xib. Add TableViewCell element. Drag on it

3条回答
  •  情书的邮戳
    2020-12-10 06:56

    Do not use UITableViewCell's initializer, but make the cell load from your nib:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        static NSString *CellIdentifier = @"EditCell";
    
        EditCell *cell = (EditCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"YourNibNameHere" owner:self options:nil];
            cell = (EditCell *)[nib objectAtIndex:0];
        }
        cell.editRow.text = @"some text to test";
        return cell;
    }
    

    Of course, you need to specify the correct nib name.

提交回复
热议问题