2016-02-12 71 views
0

我想添加自定义tableviewcell分离这样如何添加自定义tableviewcell分隔符?

------------ -----------细胞

---定制sperator ---

------------ -----------细胞

---定制sperator ---

我试过了

  1. 添加下面的UIView在细胞和故事板连接

    @IBOutlet weak var sperator: UIView! 
    
  2. addcode在cellForRow的cellForRowAtIndexPath

    override func tableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("MainListCell",forIndexPath: indexPath) as! MainTableViewCell 
    
    let list = List(index: indexPath.row) 
    
    
    cell.titleLabel.text = list.title! 
    cell.titleIcon.image = list.icon! 
    cell.detailTitleLabel.text = list.detailtitle! 
    cell.coinCountLabel.text = "X0" 
    cell.addSubview(self.sperator) 
    
    return cell 
    } 
    

,但是,我可以看到的UIView :(

+0

为什么不为你的分隔符行使用不同的单元格类型 - 相应地增加'numberOfRowsInSection'值,然后返回'cellForRowAtIndexPath'中的正确类型的单元格 – Paulw11

+0

@ Paulw11谢谢!但我可以修复不同的方式。 cell.constent.addSubview(sperator) –

+0

只要确保在重新使用单元格时不再添加分隔符 – Paulw11

回答

0

如果更改一个代码,你可以看到speer line

cell.contentView.caddSubview(self.sperator)