时,这是我的应用程序:编辑单元格网点编辑的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