[英]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.