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

标签 ios swift uitableview xcode7 xib

我正在处理 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/

相关文章:

ios - 嵌入式设备上可通过 iOS 访问的 WebService

ios - Interface Builder 文件中的未知类 _TtC8<appName>20MasterViewController

ios - 处理URLSession时是否总是需要[Weak self]?

iphone - 有谁知道 UIDataDetectorTypeCalendarEvent 在 UITextView 中如何工作?

iOS Swift 4 - Twitter 登录按钮不执行任何操作 - 返回线程 1 Sigabrt,没有堆栈跟踪

iphone - 更新 IOS 应用程序。是否需要审查更新?

ios - 加载 URL 时 UIWebView 崩溃

iPhone - 如何使用 TableView 单元格?

ios - UITableView 不填充数据

ios - Swift - 当没有数据时,UISearchBar 没有结果消息显示