ios - 如何添加自定义tableviewcell分隔符?

标签 ios xcode swift uiview

我想添加像这样的自定义tableviewcell分隔符

------------单元格------------

---自定义sperator---

------------单元格------------

---自定义sperator---

我试过了

  1. 在 Storyboard 中的单元格下方添加 uiview 并连接

    @IBOutlet weak var sperator: UIView!
    
  2. 在 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 :(

最佳答案

如果你改变一个代码,你可以看到sperator行

cell.contentView.caddSubview(self.sperator)

关于ios - 如何添加自定义tableviewcell分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35354088/

相关文章:

ios - 按下按钮时截取部分屏幕截图

arrays - 静态 TableView 中数组中的复杂json数据数组(详细信息)

ios - 如何在 UINavigationBar sizeToFit 中设置 UITextField?

ios - popToRootViewControllerAnimated 后崩溃

xcode - 通过 App Store 安装时卸载 Xcode 4

ios - Xcode 5 在打开 Storyboard时意外退出

ios - 如何通过presentViewController 将对象传递到 View 中?

iphone - iOS - 检测游戏中心是否被禁用

iphone - iOS 多个委托(delegate)

ios - 如何快速返回多个值