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?
There are two variants to register , but both take a parameter called forCellReuseIdentifier , which is a string that lets you register different kinds of table view cells. For example, you might have a reuse identifier "DefaultCell", another one called "Heading cell", another one "CellWithTextField", and so on.
Registering the cell We need a way to tell the UITableView to use our new cell instead of the default cell. To do that we register the XIB file in the view controller that has the UITableView . Then, open HabitsTableViewController. swift to finish registering the cell.
For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.
-(void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"cell" bundle:nil]
forCellReuseIdentifier:@"cell"];
}
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"];
For Swift
tableViewSubCategory.register(UINib(nibName: "", bundle: nil), forCellReuseIdentifier: "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With