時,這是我的應用程序:編輯單元格網點編輯的tableview
當我按下編輯鍵( '' Rediger ''),我得到如下:
所以我的問題是:如何在編輯tableview時隱藏圓形紅圈和隱藏指示符?圓圈和披露指標都是imageViews。
下面是自定義單元格代碼(i編輯了不必要的部分):
class KundeavisCell: UITableViewCell {
@IBOutlet weak var unreadImage: UIImageView!
@IBOutlet weak var disclosureIndicatorImage: UIImageView!
}
並與表視圖控制器:
class KundeaviserVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var redigerOutlet: UIBarButtonItem!
var stores = ["Rema 1000", "Coop Obs", "Coop Extra"]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "KundeavisCell", for: indexPath) as! KundeavisCell
// Here i edit the cell
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return stores.count
}
@IBAction func tableViewEditingPressed(_ sender: Any) {
if tableView.isEditing {
tableView.setEditing(false, animated: true);
redigerOutlet.style = UIBarButtonItemStyle.plain;
redigerOutlet.title = "Rediger";
} else {
tableView.setEditing(true, animated: true);
redigerOutlet.title = "Ferdig";
redigerOutlet.style = UIBarButtonItemStyle.done;
}
}
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let itemToMove = stores[sourceIndexPath.row]
stores.remove(at: sourceIndexPath.row)
stores.insert(itemToMove, at: destinationIndexPath.row)
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.none
}
func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false
}
}
我知道可以縮進圖像通過對它們設置約束來左邊,但我想完全隱藏它們。我發現了一個關於它的問題:Link,但不幸的是它是在5年前和Objective-C中編寫的。
任何幫助將不勝感激,謝謝!
不幸的是我沒有在Swift中編寫代碼。但是,嘗試子類化您的UITableViewCell並重寫** setEditing:animated:**,如在此線程中提到的:http://stackoverflow.com/questions/19678695/customising-cell-editing-style-in-uitableview-in-ios,從那裏你可以設置你的ImageViews隱藏= YES/NO取決於你如何編輯/停止編輯。 – 2017-02-12 23:08:51