Register nib name for tableView

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?

+12
source share
9 answers
 -(void)viewDidLoad { [super viewDidLoad]; [self.tableView registerNib:[UINib nibWithNibName:@"cell" bundle:nil] forCellReuseIdentifier:@"cell"]; } 
+24
source

Apple has provided a register method for UITableView after iOS 5. Please see the link to the class http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Example:

  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"]; 
+2
source
  (void)viewDidLoad { [super viewDidLoad]; [_tbl_setpaper registerNib:[UINib nibWithNibName:@"SetPaperCell" bundle:nil] forCellReuseIdentifier:@"Cell"]; } 

Just put oneline in your viewdidload, you should have a table output, cell id, cell class.

+2
source
 static NSString *cellIdentifier = @"cell"; if (tableView ==tableview1) { ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell1 == nil) { cell1 = [tableview dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; } } 
0
source
 // First of all Declare an IBOutlet for your customCell in Your View Controller IBOutlet ScoreCell *scoreCell; // Synthesize it. // Assign your view controller class to File Owner of your custom cell (Eg. File Owner of ScoreCell.xib) // Then Assign Reference Outlet of ScoreCell.xib with Object 'scoreCell' // Finally Create your custom Cell as follow : ScoreCell *cell = (ScoreCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; cell = [nib objectAtIndex:0]; } 
0
source

Registers an nib object containing a cell with a table view under the specified identifier.

 - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier Parameters 

NIB An nib object that indicates the nib file that will be used to create the cell. This parameter cannot be zero. identifier The reuse identifier for the cell. This parameter should not be nil and should not be an empty string.

This doc can help you.

0
source

See here: http://mrmaksimize.com/Custom-UITableViewCell-With-NIB/

  - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerNib:[UINib nibWithNibName:@"EXCustomCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CustomCellReuseID"]; } 

Later in code:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCellReuseID"; EXCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell... [cell.cellItemImage setImage:[UIImage imageNamed:@"glyphicons_428_podium"]]; [cell.cellItemLabel setText = @"Mr Burns."]; return cell; } 
0
source

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

This code is working fine

0
source

For Swift

 tableViewSubCategory.register(UINib(nibName: "", bundle: nil), forCellReuseIdentifier: "") 
0
source

All Articles