这是我的应用程序:

当我按下编辑按钮(''Rediger'')时,我得到以下信息:

因此,我的问题是:如何在编辑表视图时隐藏圆形红色圆圈和显示指示器?圆圈和披露指标都是imageViews。
下面是自定义单元格的代码(我去掉了不必要的部分):
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编写的。
我们将非常感谢您的帮助,谢谢!
发布于 2017-02-13 07:59:02
您引用的代码到现在仍然有效。您已经有了UITableViewCell的自定义实现,所以现在实现SetEditing函数,并在实现中隐藏/显示您的图像。
override func setEditing(_ editing: Bool, animated: Bool) {
unreadImage.isHidden = editing
disclosureIndicatorImage.isHidden = editing
}这应该行得通。
https://stackoverflow.com/questions/42194303
复制相似问题