I need to load the custom cell with a NIB associated in a table without using "dequeueReusableCellWithIdentifier:"
The cells must be loaded new, do not want to reuse the old ..
suppose that the class is called "CustomCell.h and CustomCell.m" and the NIB CustomCell.xib
How can I allocate and initialize the cell does not use them?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = ??
//cell customization
return cell
}
How to solve the issue?
You can load CustomCell with loadNibNamed
method of NSBundle as follow.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"NibFile" owner:self options:nil] objectAtIndex:0]
//cell customization
return cell
}
Why you don't want to reuse the cell ? any specific reason ? It would be more memory consuming as each time it will create a new cell. You can use code as follow to reuse if you need,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"CellIdentifier";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell)
cell = [[[NSBundle mainBundle] loadNibNamed:@"NibFile" owner:self options:nil] objectAtIndex:0]
//cell customization
return cell
}
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