所以我在导航栏下有一个表格 View ,当用户在搜索栏中输入内容时会显示该表格 View 。一切似乎都能找到。但是在我推送 View Controller 后,当用户在 tableview 中选择一个单元格时,我的 tableview 被搞砸了,然后从 detailViewController 返回。
• 问题:当我在 detailViewController 中按下后,导航栏覆盖了表格 View 的最顶部单元格。但这并不是一开始就发生的。
• 我试过了:
1. Toggled 'Under Top Bars' in the storyboard
2. Check all my constraint
This is how added the tableview onto the subview
func updateSearchResults(for searchController: UISearchController) {
// When the user is typing
if let searchText = searchController.searchBar.text, !searchText.isEmpty {
// add the tableview onto the subview
view.addSubview(tableView)
self.searchController.dimsBackgroundDuringPresentation = false
// filter the username array, to match the text in the search bar
filteredUsernames = unfilterdUsernames.filter({ (username) -> Bool in
return username.lowercased().contains(searchText.lowercased())
})
if let usernames = filteredUsernames {
getUsersFromUsernames(usernames: usernames, completion: { (users) in
self.filteredUsers = users
})
}
// else, the user is not typing anything. Remove the tableview from the subview
} else {
self.searchController.dimsBackgroundDuringPresentation = false
tableView.removeFromSuperview()
filteredUsernames = unfilterdUsernames
}
// reload tableview data
tableView.reloadData()
}
这就是我进入 detailViewController 的方式:
tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
// the profile view that I want to display, after the user select one of the tableViewCell
let profileController = UIStoryboard(name: "rofile", bundle: nil).instantiateViewController(withIdentifier: "profile") as? ProfileCollectionViewController
// user is the value that I want to transfer to the profileController
// which user from the indexPath in tableView
if let user = filteredUsers?[indexPath.row] {
userToPass = user
// set the delegate to self
profileController?.userDataDelegate = self
// push a navigationController to profileController
self.navigationController?.pushViewController(profileController!, animated: true)
在进入detailViewController之前:
从 detailViewController 按下返回按钮后:
The first index is covered by the navigation controller
转到 Storyboard。
选择 ViewController(不是表格 View 或导航 Controller )。
在属性检查器中,取消选中 Adjust Scroll View Insets
关于ios - 按下 'Back' 后,TableView 单元格被导航覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43329515/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |