初始化带有标识符的ViewController后隐藏的导航栏

时间:2017-07-06 18:06:47

标签: swift chat navigationbar

我正在尝试与我的应用聊天,但我仍然有这个问题。正如您所看到的,我有一个ChatListTableViewController,其中包含所有活动聊天的列表(图片1,左上角视图)。当我点击一个单元格时,我成功打开了ChatViewController,其中NavBar显示了我聊天的人的姓名,后退箭头和垃圾按钮可以删除聊天。但是,在ChatListTableViewController中我有一个“+”按钮(图片1,左上角),它打开一个PopUpViewController:这个允许你开始与从TableView中选择的用户进行新的聊天。从图1可以看出,当我点击PopUpChatListViewController中的一个单元格时,我尝试初始化一个ChatViewController并打开但导航栏被隐藏。这是通过使用TableView的函数“didSelectRowAt”来完成的。 。我发布了PopUpChatListViewController的代码。在ChatViewController的viewDidLoad中,我尝试将set“navigationBar.isHidden = false”设置为但没有。你能解释一下这里发生了什么吗?

DoesFileExist("c:\temp\file*.*");
private static bool DoesFileExist(string file2)
{
  var resultfiles = Directory.GetFiles(file2).Where(file => new FileInfo(file).CreationTime.Date == DateTime.Today.Date);

  if (resultfiles.Count() > 0)
  {
    return true;
  }

  return false;
}

The file2 ends up being c:\\temp\\file*.*.

观看屏幕运行APP的视图:

enter image description here

主要故事节目方案:

enter image description here

2 个答案:

答案 0 :(得分:1)

如果您想使用push segue,请检查@Leo Valentim的答案。如果您仍想使用modal segue,我的回答是给您的。

更改此代码:

public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    UserDefaults.standard.set(userID[indexPath.row], forKey: "chatID")    

    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ChatActivity") as! ChatViewController

    self.present(vc, animated: true, completion: nil)
}

要:

public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    UserDefaults.standard.set(userID[indexPath.row], forKey: "chatID")    

    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ChatActivity") as! ChatViewController
    let navigationController = UINavigationController()
    navigationController.viewControllers = [vc]

    self.present(navigationController, animated: true, completion: nil)
}

您可以参考以下问题:Modal segue, navigation bar disappears

在这里:Using Segues(注意表9-1自适应segue类型,它包括每种类型的segue类型和行为)

答案 1 :(得分:0)

替换

self.present(vc, animated: true, completion: nil)

self.navigationController?.pushViewController(vc, animated: true)

当您使用' present'视图丢失了de navigationController。

相关问题