[英]Custom cell imageView shifts to left side when editing tableView
我有一個tableView,我需要能夠從其中刪除項目,但是,當我從編輯模式放回tableView時,自定義單元格中的imageView會移到左側。 以下是一些相關的代碼和圖像:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! NotificationsTableViewCell
cell.storiesLabel.text = stories[indexPath.row].name
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.shouldIndentWhileEditing = false
if stories[indexPath.row].notificationBool == true {
cell.notificationImageView.image = UIImage(named: "notifications_filled.png")
}
else {
cell.notificationImageView.image = UIImage(named: "notifications.png")
}
return cell
}
func editFollowedStoriesTableView() {
if tableView.editing == true {
tableView.setEditing(false, animated: false)
}
else {
tableView.setEditing(true, animated: false)
}
}
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if(self.tableView.editing){
return UITableViewCellEditingStyle.Delete
}
return UITableViewCellEditingStyle.None
}
如何防止第二張圖片發生? 任何幫助都非常有用!
您有一些相互矛盾的自動布局約束。 您需要刪除UIImageView上的以下約束之一:
Width
Leading Space to: Label
Trailing space to: Superview
在此,前導空間和尾隨空間約束定義了imageView的寬度。 然后,您添加了執行相同操作的寬度約束。 現在,如果您希望圖像視圖具有固定的寬度,請刪除前導空間或尾隨空間約束。 如果不需要固定寬度,請刪除寬度約束。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.