按下'后退'?

时间:2017-04-10 17:34:46

标签: ios iphone swift uitableview

所以我在导航栏下面有一个tableview,当用户在搜索栏中输入内容时,它会显示出来。一切似乎都找不到。但是当我推动一个视图控制器,当用户在tableview中选择一个单元格,然后从detailViewController返回时,我的tableview被搞砸了。

问题:在我按下detailViewController之后,导航栏覆盖了tableview的最顶层单元格。但这并不是在一开始就发生的。

•我试过了:

   1. Toggled 'Under Top Bars' in the storyboard
   2. Check all my constraint
  

这就是将tableview添加到子视图

的方法
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之前:

enter image description here

从detailViewController按下后退按钮:

  

第一个索引由导航控制器

覆盖

enter image description here

1 个答案:

答案 0 :(得分:0)

转到故事板。

选择ViewController(不是表格视图或导航控制器)。

在属性检查器中,取消选中Adjust Scroll View Insets