Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将两个.xib文件添加到两个不同的部分_Ios_Swift_Uitableview_Xcode7_Xib - Fatal编程技术网

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

Ios 如何将两个.xib文件添加到两个不同的部分,ios,swift,uitableview,xcode7,xib,Ios,Swift,Uitableview,Xcode7,Xib,我正在开发UITableView。我需要有两个不同的部分,每个部分应该有一个.xib文件。一个xib可以很好地工作,但我无法同时做到这两个。让我困惑的是,我不知道如何在代码中添加第二个xib的控制器。如果你能告诉我逻辑,我将不胜感激。谢谢。很简单 您可以使用以下方法注册nib文件: -(void)registerNibs { [self.tableView registerNib:[UINib nibWithNibName:@"CellType1" bundle:[NSBundle ma

我正在开发UITableView。我需要有两个不同的部分,每个部分应该有一个.xib文件。一个xib可以很好地工作,但我无法同时做到这两个。让我困惑的是,我不知道如何在代码中添加第二个xib的控制器。如果你能告诉我逻辑,我将不胜感激。谢谢。

很简单

您可以使用以下方法注册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"];
这很容易

您可以使用以下方法注册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"];