tobeiosdev tobeiosdev - 7 months ago 27
Swift Question

While commitEditingStyle in tableView, imageView height goes big overflow?

I find that while swipe Left for commitEditingStyle in tableView, including imageView goes a bit down (overflow), where is my fault? I have added some informations about what I did.

Using auto layouts 0 to each side Superview:

enter image description here

Setting tableView rowHeight like this in viewDidLoad:

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

}


Here's my commitEditingStyle func for tableView:

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

Answer

I solved this problem adding this,

cell.recipeImg.layer.masksToBounds = true

in cellForRowAtIndexPath: method while imageView adding.