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?