我会使用动态原型单元。然后,我会设置ViewController
as thedelegate
和dataSource
. 然后,我将创建一个自定义子类,UITableViewCell
并将第二部分的元素连接到IBOutlet
custom 中的 s UITableViewCell
。
如果第一部分不能用一种通用单元类型完成,我也会UITableViewCell
为该部分创建一个自定义子类。
然后我会使用该cellForRowAtIndexPath:
方法来设置单元格,其中包含我想要的信息。因此,如果我使用的第一部分FirstSectionCell
和我的第二部分用作我的SecondSectionCell
自定义子类,则如下所示:UITableViewCell
cellForRowAtIndexPath:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section==0)
{
FirstSectionCell *firstCell = [tableView dequeueReusableCellWithIdentifier:@"First Cell Prototype"];
//Set up the first cell.
return firstCell;
}
else if(indexPath.section ==1)
{
SecondSectionCell *secondCell = [tableView dequeueReusableCellWithIdentifier:@"Second Cell Ptototype"];
//Set up second cell.
secondCell.someLabel.text = @"whatever";
//etc.
return secondCell;
}
else
{
//if you have another section handle it here.
}
}