// 注册nib
tableView.registerNib(UINib(nibName: "nibName", bundle: mainBundle), forCellReuseIdentifier: "cellIdentifier")
// 注册类
tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: "cellIdentifier")
// 数据源
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as! TableViewCell
return cell
}
使用注册类的时候需要手写代码
重写init(style: UITableViewCellStyle, reuseIdentifier: String?)方法,并在里面进行UI设置
ps: 网上搜自定义cell教程还是挺多的
在UITableview等涉及cell的重用的界面中,cell上的按钮点击事件RAC响应会随着cell的重用多次触发,并导致cell无法释放cell上添加按钮
在cell对象中触发按钮的RAC点击事件
在不滚动界面的情况下点价按钮只响应了一次
滚动界面后点击按钮,直接打印了四个log
这个问题是由于cell重用导致的,需要解除signal在重用时的绑定。
滚动界面触发按钮事件查看log
嘿嘿,只有一次啦,成功解决
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)