2015-10-06 65 views

回答

1

是的,你可以做到这一点,例如:

switch indexPath.row { 
case 0: 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell1", forIndexPath: indexPath) as! FirstTableViewCell 
case 1: 

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as! SecondTableViewCell 
default: 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell3", forIndexPath: indexPath) as! ThirdTableViewCell 
} 
0

UITableViewCell的需要,你可以用它来指代他们的个人标识。

A UITableView可以具有多个具有不同标识符的默认单元。

在界面构建器上,选择您的UITableView,然后在属性检查器中更改Prototype Cells的值以符合您的需求。

enter image description here

然后,选择单元格,并为其分配一个唯一的标识符。

enter image description here

如果您使用代码来创建UITableView,你必须注册为每个唯一标识符UITableViewCell子类:

tableView.registerClass(MyTableViewCell.self, forCellWithReuseIdentifier: "MyCell") 
tableView.registerClass(AnotherTableViewCell.self, forCellWithReuseIdentifier: "MyCell") 

不管你如何注册你的细胞,然后,可以决定使用哪个原型单元UITableView s代表方法

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
相关问题