我有 tableView cellForRowAtIndexPath
功能:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: ProjectCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! ProjectCell
let rightUtilityButtons = NSMutableArray()
rightUtilityButtons.sw_addUtilityButtonWithColor(UIColor(red: 255.0/255.0, green: 200.0/255.0, blue: 122.0/255.0, alpha: 1.0), icon: UIImage(named: "ic_edit"))
rightUtilityButtons.sw_addUtilityButtonWithColor(UIColor(red: 255.0/255.0, green: 120.0/255.0, blue: 122.0/255.0, alpha: 1.0), icon: UIImage(named: "ic_close"))
cell.setRightUtilityButtons(rightUtilityButtons as [AnyObject], withButtonWidth: 70)
cell.delegate = self
let project = projects[indexPath.row] as! Project
cell.projectNameLabel.text = project.name
cell.projectDescriptionLabel.text = project.desc
cell.projectDateLabel.text = project.duedate
cell.customView.backgroundColor = getColor(indexPath.row * 10)
cell.backView.layer.cornerRadius = 6
cell.backView.layer.shadowColor = UIColor.blackColor().CGColor
cell.backView.layer.shadowOffset = CGSize(width: -1, height: 1)
cell.backView.layer.shadowOpacity = 0.5
return cell
}
问题在这里:
cell.backView.layer.shadowColor = UIColor.blackColor().CGColor
cell.backView.layer.shadowOffset = CGSize(width: -1, height: 1)
cell.backView.layer.shadowOpacity = 0.5
如果没有这段代码,我的 TableView 会很好用。如何解决这个问题呢。也许我的单元格 View 更好的地方是 willDisplayCell,但是如何将这段代码放在那里?
最佳答案
将设置阴影的代码移动到单元格的初始化。现在,每次委托(delegate)将单元格返回到 TableView 时都会设置阴影。对于刚刚被重复使用并且已经配置了阴影的单元格,您不必执行此操作。
记得在处理阴影时设置
shadowPath
。它提高了性能。[view.layer setShadowPath:[[UIBezierPath bezierPathWithRect:view.bounds] CGPath]];
关于ios - UITableView 卡住单元格。如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33609544/