2016-02-28 56 views
0

我正在设计一个3个自定义单元格的tableview。 我想通过添加唯一的附件类型来定制它们。 我已经crating一个tableViewController与静态单元格。每个单元格我都写了一个特殊的标识符和特殊类。我应该在tableView(_:cellForRowAtIndexPath :)方法中写入自定义单元格?

我的tableView基金应该如何为3个自定义单元格?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let CityCellIdentifier = "CityTableViewCell" 

    let cell = tableView.dequeueReusableCellWithIdentifier(CityCellIdentifier, forIndexPath: indexPath) as! CityTableViewCell 
    // Configure the cell... 

    return cell 
} 

我应该为此创建三个单元变量吗?

+0

http://stackoverflow.com/questions/14303832/uitableview-with-two-custom-cells-multiple-identifiers –

+0

他的问题很快,你将他链接到一个客观的c问题 – Shades

+0

你的意思是tableview最多包含3个(不同的)单元格,或者tableview会显示多个单元格,它们可以是3种不同的类型? – Kymer

回答

0

每我的回答here,使用自己下面的代码的变化:

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? { 

    if (criteria for cell 1) { 
     let cell = tableView!.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as? cell1 
     return (cell) 
    } 
    else { 
     let cell = tableView!.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as? cell2 
     return (cell) 
    } 
} 
相关问题