ios - 按下 'Back' 后,TableView 单元格被导航覆盖?
<p><p>所以我在导航栏下有一个表格 View ,当用户在搜索栏中输入内容时会显示该表格 View 。一切似乎都能找到。但是在我推送 ViewController 后,当用户在 tableview 中选择一个单元格时,我的 tableview 被搞砸了,然后从 detailViewController 返回。 </p>
<p>• 问题:当我在 detailViewController 中按下后,导航栏覆盖了表格 View 的最顶部单元格。但这并不是一开始就发生的。</p>
<p>• 我试过了:</p>
<pre><code> 1. Toggled 'Under Top Bars' in the storyboard
2. Check all my constraint
</code></pre>
<blockquote>
<p>This is how added the tableview onto the subview</p>
</blockquote>
<pre><code>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()
}
</code></pre>
<p>这就是我进入 detailViewController 的方式:</p>
<blockquote>
<p>tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)</p>
</blockquote>
<pre><code>// 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? {
userToPass = user
// set the delegate to self
profileController?.userDataDelegate = self
// push a navigationController to profileController
self.navigationController?.pushViewController(profileController!, animated: true)
</code></pre>
<p>在进入detailViewController之前:</p>
<p> <a href="/image/6v9SW.png" rel="noreferrer noopener nofollow"><img src="/image/6v9SW.png" alt="enter image description here"/></a> </p>
<p>从 detailViewController 按下返回按钮后:</p>
<blockquote>
<p>The first index is covered by the navigation controller</p>
</blockquote>
<p> <a href="/image/BMeMv.png" rel="noreferrer noopener nofollow"><img src="/image/BMeMv.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>转到 Storyboard。 </p>
<p>选择 ViewController(不是表格 View 或导航 Controller )。</p>
<p>在属性检查器中,取消选中 <code>Adjust Scroll View Insets</code></p></p>
<p style="font-size: 20px;">关于ios - 按下'Back' 后,TableView 单元格被导航覆盖?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/43329515/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/43329515/
</a>
</p>
页:
[1]