2017-02-28 35 views
1

我的iOS應用程序使用UITableViewController來顯示錶格視圖。內置的編輯按鈕切換到編輯模式。有些單元需要顯示附件視圖,這是通過設置cell.accessoryType = .detailButton完成的。同時在所有單元上設置了cell.editingAccessoryType = .none。在編輯模式下,單元格還顯示重新排序,刪除和插入附件視圖。UITableView:在編輯模式下單元格附件視圖的外觀不正確

問題

的問題是,切換到編輯模式時,所述附件視圖留下的一些細胞,並移動到該單元的左上角。這似乎是隨機發生的。

下面是其中配置每個單元的代碼:

private func tableView(_ tableView: UITableView, cellForTextFragment fragment: Fragment, at indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: basicCellIdentifier, for: indexPath) as! BasicFragmentCell 
    cell.contentTextField.text = fragment.value 
    cell.showsReorderControl = true 

    switch fragment.type { 
    case .phoneNumber, .email: 
     cell.accessoryType = .detailButton 

    default: 
     cell.accessoryType = .none 
    } 
    cell.editingAccessoryType = .none 

    return cell 
} 

完整的源是在GitHub:https://github.com/lukevanin/OCRAI

編輯模式

Incorrect positioning of accessory view

非編輯模式

enter image description here

回答

0

一種解決方法是使用標準的UIViewController具有嵌入UITableView,而是採用一個UITableViewController

爲了進行編輯以正確地工作,編輯模式需要在編輯狀態在UIViewController上改變時在UITableView上明確設置,例如,

override func setEditing(_ editing: Bool, animated: Bool) { 
    super.setEditing(editing, animated: animated) 
    tableView.setEditing(editing, animated: animated) 
} 
相關問題