【问题标题】:Change CellReuseIdentifier Based on section根据部分更改单元重用标识符
【发布时间】:2012-07-22 09:20:06
【问题描述】:

我有一个 UITableView 和一些具有不同表格视图样式的 .xib。每个 .xib 都有它自己的类,并使用基于该部分的重用标识符进行注册。例如: 在我的 viewDidLoad 中,我有以下内容:

UINib *cellStyleOne = [UINib nibWithNibName:@"CellStyleOne" bundle:nil];
[self.tableView registerNib:cellStyleOne forCellReuseIdentifier:@"CellStyleOne"];

UINib *cellStyleTwo = [UINib nibWithNibName:@"CellStyleTwo" bundle:nil];
[self.tableView registerNib:cellStyleTwo forCellReuseIdentifier:@"CellStyleTwo"];

UINib *cellStyleThree = [UINib nibWithNibName:@"CellStyleThree" bundle:nil];
[self.tableView registerNib:cellStyleThree forCellReuseIdentifier:@"CellStyleThree"];

如何将这些重用标识符中的每一个分配给我的 cellForRowAtIndexPath 中的一部分单元格而不引起任何问题?

谢谢。

【问题讨论】:

    标签: objective-c uitableview xib reuseidentifier


    【解决方案1】:

    您可以在cellForRowAtIndexPath: 中返回您喜欢的任何单元格,只需执行类似的操作

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.section == 0)
        {
            //create and return a cell with reuse ID: @"CellStyleOne"
        }
        else 
        {
            //create and return a cell using a different reuse ID
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多