【问题标题】:Navigation bar disappears when come back again再次返回时导航栏消失
【发布时间】:2016-12-06 07:11:41
【问题描述】:

我在TableView 之上使用UINavigationBar。每当我触摸 cell 并再次回到 TableView 时,NavigationBar 就会消失。我该怎么办?

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        if indexPath.section == 0{

             let cell =  tableView.dequeueReusableCell(withIdentifier: fa_color_arrayOfCellData[indexPath.row].cell, for: indexPath) as UITableViewCell

            let (fa_ColorArgumentsContent) = fa_color_arrayOfCellData[indexPath.row].text
            cell.textLabel?.text = fa_ColorArgumentsContent
             cell.textLabel?.textAlignment = NSTextAlignment.right


            //set the data here
            return cell
        }
        else if indexPath.section == 1 {
            let cell =  tableView.dequeueReusableCell(withIdentifier: fa_system_arrayOfCellData[indexPath.row].cell, for: indexPath) as UITableViewCell

            let (fa_SystemArgumentsContent) = fa_system_arrayOfCellData[indexPath.row].text
            cell.textLabel?.text = fa_SystemArgumentsContent
            cell.textLabel?.textAlignment = NSTextAlignment.right

            //set the data here
            return cell
        }
        else if indexPath.section == 2{
            let cell =  tableView.dequeueReusableCell(withIdentifier: fa_support_arrayOfCellData[indexPath.row].cell, for: indexPath) as UITableViewCell

            let (fa_SupportArgumentsContent) =  fa_support_arrayOfCellData[indexPath.row].text
            cell.textLabel?.text = fa_SupportArgumentsContent
             cell.textLabel?.textAlignment = NSTextAlignment.right


            //set the data here
            return cell
        } else {

            let cell =  tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell

            let (fa_SupportArgumentsContent) =  fa_color_arrayOfCellData[indexPath.row].text
            cell.textLabel?.text = fa_SupportArgumentsContent
             cell.textLabel?.textAlignment = NSTextAlignment.right

            return cell

    }

【问题讨论】:

  • 您是否将视图控制器嵌入到 uinavigation 控制器中?
  • @Tj3n 是的,我愿意。
  • 在你的 viewdidapper() 中写一行 self.navigationController.navigationBarHidden = NO;
  • hmm...它不应该只是消失,您是否创建 segue 以在您触摸单元格后指向视图控制器?
  • @fatemeh 你能解释一下你是不是在点击单元格时推动另一个视图控制器,当你回来时你弹出那个控制器吗?

标签: ios swift uitableview uinavigationbar


【解决方案1】:
override func viewWillAppear(animated: Bool) {
    self.navigationController?.navigationBarHidden = false
}

在下一个控制器中使用

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.navigationBarHidden = false
}

还有

override func viewWillAppear(_ animated: Bool) {
    // Hide the navigation bar on the this view controller
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
    // Show the navigation bar on other view controllers
    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

【讨论】:

  • 你在做什么推送或展示??
  • 你用哪一行来隐藏导航栏?
【解决方案2】:

取消隐藏时再次将委托分配给navigationController

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    相关资源
    最近更新 更多