在tableView中使用commitEditingStyle时,imageView高度会大幅溢出?

时间:2016-04-07 16:21:12

标签: ios swift uitableview autolayout tableviewcell

我发现在tableView中向左扫描commitEditingStyle时,包括imageView有点下降(溢出),我的错在哪里?我已经添加了一些关于我所做的事情的信息。

对每一方使用自动布局 0 Superview

enter image description here

viewDidLoad 中设置 tableView rowHeight

override func viewDidLoad() {
    super.viewDidLoad()

    // deleting top tableView spacing..
    tableView.contentInset = UIEdgeInsetsZero
    self.automaticallyAdjustsScrollViewInsets = false

    // set rowHeight
    tableView.rowHeight = (self.view.frame.height - self.navigationController!.navigationBar.frame.size.height - 20) / 4

    tableView.delegate = self
    tableView.dataSource = self

}

这是 tableView commitEditingStyle 功能:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    if editingStyle == .Delete {
        let city = cities[indexPath.row]
        ad.managedObjectContext.deleteObject(city)
        do {
            try ad.managedObjectContext.save()
        }
        catch {
            fatalError("Error deleting item!")
        }

        fetchAndSetResults()

    } else if editingStyle == .Insert {
        // ..
    }
}

enter image description here

2 个答案:

答案 0 :(得分:0)

只需添加"剪辑子视图"如果您有" Aspect Fill"在单元格中的ImageView。模式。

答案 1 :(得分:0)

我解决了这个问题,添加了这个,

cell.recipeImg.layer.masksToBounds = true
在imageView添加时

cellForRowAtIndexPath:方法中。