簡體   English   中英

具有不同單元格的自定義tableview

[英]Custom tableview with different cell

我是iOS新手。 我有一個表格視圖,我想在其中加載不同的自定義單元格。

這是我來自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;
}

在方法n umberOfRowsInSections:(UITableView *) tableview我有:

    if (tableView.tag==SEARCH)
    {
        return [firstList count];
    }
    else
    {
        return [secondList count];
    }

我的問題是每次執行ELSE時,tableview都包含第一個和第二個CustomCell。 為什么?

我終於找到了問題。 else分支上使用的標識符實際上是CustomCell * cell = ..(如果分支)使用的標識符。 沒有Cella標識符:)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM