是因为UITableViewCell的默认删除样式是带有角度的。当我们调用deleteRows(at:with:)方法删除某一行时,UITableViewCell会根据默认的删除样式进行动画效果的展示。
要解决这个问题,我们可以通过自定义UITableViewCell的删除样式来改变边框的角度。具体步骤如下:
下面是示例代码:
class CustomTableViewCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
contentView.layer.cornerRadius = 0
}
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// ...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomTableViewCell
// 配置cell的内容
return cell
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.selectionStyle = .none
}
// ...
}
通过以上步骤,我们可以解决UITableViewCell边框在删除时变得有角度的问题。
推荐的腾讯云相关产品:腾讯云移动开发平台(https://cloud.tencent.com/product/mpp)可以帮助开发者快速构建移动应用,提供丰富的移动开发工具和服务。
领取专属 10元无门槛券
手把手带您无忧上云