1

我有一个 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 中的一部分单元格而不引起任何问题?

谢谢。

4

1 回答 1

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
    }
}
于 2012-07-22T10:17:15.983 回答