【发布时间】:2017-07-06 18:06:47
【问题描述】:
我正在最终在我的应用程序中进行聊天,但我仍然遇到这个问题。如您所见,我有一个 ChatListTableViewController,其中包含所有活动聊天的列表(图 1,左上角视图)。当我单击一个单元格时,我成功打开了 che ChatViewController,其导航栏显示与我聊天的人的姓名、后退箭头和用于删除聊天的垃圾桶按钮。但是,在 ChatListTableViewController 中,我有一个“+”按钮(图 1,左上角),它打开了 PopUpViewController:这个按钮允许您与从 TableView 中选择的用户开始新的聊天。从图 1 中可以看出,问题是当我单击 PopUpChatListViewController 中的一个单元格时,我尝试初始化一个 ChatViewController,它会打开,但 NavigationBar 是隐藏的。这是通过使用 TableView 的函数“didSelectRowAt”完成的.我将 PopUpChatListViewController 的代码发布给您。在 ChatViewController 的 viewDidLoad 中,我尝试设置“navigationBar.isHidden = false”,但什么也没有。你能解释一下这里发生了什么吗?
import UIKit
class PopUpChatListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return userName.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "cellPopUp", for: indexPath)
cell.textLabel?.text = userName[indexPath.row]
return cell
}
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)
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
运行应用程序的屏幕截图视图:
主要故事板方案:
【问题讨论】:
-
你能解释一下如何以适合容器的方式发布代码吗?我总是单击“{}”按钮并复制我看到的代码在此处输入您的代码,但我总是得到这个奇怪的结果。提前谢谢你们!
标签: swift chat navigationbar