首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在编辑tableview时编辑单元格出口

在编辑tableview时编辑单元格出口
EN

Stack Overflow用户
提问于 2017-02-13 07:03:00
回答 1查看 481关注 0票数 1

这是我的应用程序:

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

因此,我的问题是:如何在编辑表视图时隐藏圆形红色圆圈和显示指示器?圆圈和披露指标都是imageViews。

下面是自定义单元格的代码(我去掉了不必要的部分):

代码语言:javascript
运行
复制
class KundeavisCell: UITableViewCell {

@IBOutlet weak var unreadImage: UIImageView!
@IBOutlet weak var disclosureIndicatorImage: UIImageView!

}

和带有表的视图控制器:

代码语言:javascript
运行
复制
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编写的。

我们将非常感谢您的帮助,谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-13 07:59:02

您引用的代码到现在仍然有效。您已经有了UITableViewCell的自定义实现,所以现在实现SetEditing函数,并在实现中隐藏/显示您的图像。

代码语言:javascript
运行
复制
override func setEditing(_ editing: Bool, animated: Bool) {
    unreadImage.isHidden = editing
    disclosureIndicatorImage.isHidden = editing
}

这应该行得通。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42194303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档