gpt4 book ai didi

ios - 如何将两个 .xib 文件添加到两个不同的部分

转载 作者:行者123 更新时间:2023-11-28 08:53:43 25 4
gpt4 key购买 nike

我正在处理 UITableView。我需要有两个不同的部分,每个部分都应该有一个 .xib 文件。一个 xib 工作正常,但我无法同时工作。让我感到困惑的一点是,我不知道如何在代码中添加第二个 xib 的 Controller 。如果您能告诉我逻辑,我将不胜感激。谢谢。

最佳答案

很简单

你可以在一个方法中注册你的 nib 文件:

-(void)registerNibs
{
[self.tableView registerNib:[UINib nibWithNibName:@"CellType1" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CellType1"];
[self.tableView registerNib:[UINib nibWithNibName:@"CellType2" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CellType2"];
}

而你在CellForRow

if (indexpath.section == 0)
cell = (CellType1 *)[tableView dequeueReusableCellWithIdentifier:@"CellType1"];
else
cell = (CellType2 *)[tableView dequeueReusableCellWithIdentifier:@"CellType2"];

关于ios - 如何将两个 .xib 文件添加到两个不同的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33623892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com