2015-10-06 60 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 
相關問題