I finally found the issue. The identifier used on else branch was actually the identifier used for the CustomCell *cell =.. (if branch). There was no Cella identifier:).
Custom tableview with different cell
-
04-07-2022 - |
Question
I am new to iOS. I have a table view where i want to load different custom cells.
Here is my code from tableViewCellForRowAtIndexPath
:
if (self.mainTableView .tag==SEARCH)
{
static NSString *cellId=@"Cella";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
NSArray *topLevelOjects= [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell=[topLevelOjects objectAtIndex:0];
}
//code goes here
return cell;
}
else
{
static NSString *mCell = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mCell];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
}
//code goes here
return cell;
}
In method numberOfRowsInSections:(UITableView *) tableview
I have:
if (tableView.tag==SEARCH)
{
return [firstList count];
}
else
{
return [secondList count];
}
The problem i have is that every time ELSE is executed the tableview contains both the first and second CustomCell. WHY?
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow