ios - 返回应用程序时取消选择 TableView 行

标签 ios uitableview

我有一个表格 View ,其中一个表格 View 单元格打开另一个应用程序。当我返回我的应用程序时,表格 View 单元格仍然突出显示。返回应用程序时取消选择表格 View 单元格的最佳方法是什么?

编辑:问题是从应用程序返回时不会调用 -viewWillAppear-viewDidAppear,因为 View 已经可见。

最佳答案

在viewDidLoad中设置通知

final override func viewDidLoad() {
    super.viewDidLoad()

    // add notification observers
    NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
}

创建方法didBecomeActive

func didBecomeActive() {
    if let indexPath = tableView.indexPathForSelectedRow {
        deselectRow(at: indexPath, animated: true)
    }
}

UIKit 文档

关于ios - 返回应用程序时取消选择 TableView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42473220/

相关文章:

ios - SpriteKit : Why does it wait one round for the score to update?( swift )

ios - 使用 swift 3 在后台打开 url?

ios - 在 UITableViewCell 上重新渲染 subview 的最佳实践

ios - swift :didSelectRowAtIndexPath

ios - Sonoff 快速配对模式如何工作?

iphone - 如何通过蓝牙将iphone/ipad与其他设备连接?

ios - 由于自动布局,在 UILabel 中获取换行符

ios - 从 UITableView 中删除行时出现 NSInternalInconsistencyException

ios - 当单元格不可见时,CellForRow 返回 nil

iphone - 将 UITableView 分隔符隐藏在 contentView 后面