Register nib name for tableView

2020-07-02 08:43发布

static NSString *cellIdentifier = @"cell";
if (tableView ==tableview1) 
{
    ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];        
    if (cell1 == nil) 
    {
        [[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self options:nil];
        cell1 = contactCustom;
    }
}

How to register nib name in viewDidLoad method before calling cellForRowAtIndex method?

9条回答
Summer. ? 凉城
2楼-- · 2020-07-02 09:11

Apple provided register nib method for UITableView after IOS 5 Please check class reference http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Ex:

     In view did load you can register nib for UITableView like below
     [tableView registerNib:[UINib nibWithNibName:@"nibName" bundle:nil] forCellReuseIdentifier:@"identifienName"];

      In cellForRowAtIndexPath
      cell =  [tableView dequeueReusableCellWithIdentifier:@"identifienName"];
查看更多
Summer. ? 凉城
3楼-- · 2020-07-02 09:13
-(void)viewDidLoad
{
   [super viewDidLoad];
   [self.tableView registerNib:[UINib nibWithNibName:@"cell" bundle:nil] 
   forCellReuseIdentifier:@"cell"];
}
查看更多
何必那么认真
4楼-- · 2020-07-02 09:13

UINib *cellNib = [UINib nibWithNibName:@"Custom_cellTableViewCell" bundle:nil]; [self.tableView registerNib:cellNib forCellReuseIdentifier:@"Custom_cellTableViewCell"];

This code is working fine

查看更多
登录 后发表回答