0

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?

4

1 回答 1

0

我终于找到了问题。else 分支上使用的标识符实际上是 CustomCell *cell =.. (如果分支)使用的标识符。没有 Cella 标识符:)。

于 2013-11-05T13:05:14.737 回答