我有带搜索栏的TableViewController,更新updateSearchResults后可以正常工作,当我更改TabBarItem并回来时出现黑屏,可能有人遇到了这个问题吗?我怎么理解,我应该清除
viewWillDisappear中的tableview

override func viewWillAppear(_ animated: Bool) {
        setNavigationBar()
        tableView.register(NewMessageTableViewCell.self, forCellReuseIdentifier: "cell")
        tableView.tableFooterView = UIView()
        super.viewWillAppear(animated)
    }
    override func viewWillDisappear(_ animated: Bool) {

        searchUsers.removeAll()
        searchController.searchBar.text = nil
        tableView.endUpdates()

        super.viewWillDisappear(animated)

    }


UITableView work like need

Change TabBarItem

TableView don't work

最佳答案

class SearchController: UISearchController {

    override func viewWillDisappear(_ animated: Bool) {
        // to avoid black screen when switching tabs while searching
        isActive = false
    }
}

关于swift - 更改后,tabBarItem TableViewController看起来像黑屏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52638825/

10-13 03:54