简体   繁体   English

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

[英]How to add two .xib files into two different sections

I am working on a UITableView. 我正在UITableView上。 I need to have two different sections and each section should have a .xib file. 我需要有两个不同的部分,每个部分都应该有一个.xib文件。 One xib works fine but I couldn't manage to make both work. 一个XIB可以正常工作,但我无法使两者同时工作。 The point that confuses me is, I cannot figure out how to add second xib's controller in the code. 令我感到困惑的是,我无法弄清楚如何在代码中添加第二个xib的控制器。 I appreciate if you can tell me the logic. 如果您能告诉我逻辑,我将不胜感激。 Thanks. 谢谢。

it's very easy 这很容易

you can register your nib files in a method : 您可以使用以下方法注册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"];
} 

and you in CellForRow 和你在CellForRow

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从不同的.xib文件浏览一个webview到另一个webview - how to navigate one webview two another webview from different .xib files 如何根据条件在一个 UITableViewCell 中填充两个不同的 xib 文件? 在斯威夫特 - How to populate two different xib files in one UITableViewCell depending on a condition? in Swift 将来自两个xib文件的两个tableview添加到主xib视图 - Add two tableviews from two xib file to main xib view 如何在xamarin中的两个xib文件之间进行筛选? - How can I segue between two xib files in xamarin? 如何自定义表视图Swift中两个不同的部分 - How to custom order two different sections in a tableview Swift 为什么一个 iOS 通用应用程序需要有两个不同的 xib 文件? - why does an iOS universal app need to have two different xib files? 如何在两个不同部分的两个不同NSMutableArray中的单元格中显示内容(两个标签和一个图像视图)。 - How to display contents(two labels and one image view) in cell from two different NSMutableArray in two different sections. 如何在同一个类中使用不同的.xib文件? - How to use different .xib files in the same class? 如何在一个 xib 中处理两个地图视图? - How to handle two map view in one xib? 如何处理自定义UITableViewCell XIB中的两个视图? - How to handle two views in custom UITableViewCell XIB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM