【发布时间】:2017-09-05 20:55:34
【问题描述】:
所以我在导航栏下有一个表格视图,当用户在搜索栏中输入内容时会显示该表格视图。一切似乎都能找到。但是在我推送视图控制器后,当用户在 tableview 中选择一个单元格时,我的 tableview 被搞砸了,然后从 detailViewController 返回。
• 问题:当我在detailViewController 中按下后,导航栏覆盖了表格视图的最顶部单元格。但这并不是一开始就发生的。
• 我试过了:
1. Toggled 'Under Top Bars' in the storyboard
2. Check all my constraint
这就是将表格视图添加到子视图的方式
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: "Profile", 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 按下返回按钮后:
第一个索引被导航控制器覆盖
【问题讨论】:
-
该行真的存在并被覆盖吗?还是“babi”是表中唯一的一行?换句话说,当你从“profile”视图“回来”时,你能拉下桌子看到最上面一行(包含“jajang”)吗?
-
@DonMag 是的,顶行是“jajang”,但顶行被导航栏覆盖(在我从详细视图中按下后退按钮后)。这意味着我仍然可以向下滚动。一开始不是这样的。
-
好的 - 当您向下滚动并松开手指时...顶行 保持 可见吗?还是它在导航栏下“弹回”?
-
它会在导航栏下方快速恢复。但我很确定我没有改变任何高度或约束
-
我建议:当您第一次看到表格并且它看起来正确时,进入调试视图层次结构并注意约束和值...当您“回来”并且第一行是在导航栏下,再次调试视图层次结构并查找差异。另外...确保您的代码没有添加多个表视图。
标签: ios iphone swift uitableview