1

I'm needing to have either a bar or some space up at the top of my JSQMessagesVC to allow users to get back out of it, but adding elements in the storyboard doesn't work because I guess the chatVC is overriding everything in the storyboard? It also leads me to believe that getting a nav controller hooked up to my ChatVC wouldn't do anything because it's going to be overridden by the code.

I've got about 4 pages, but I'm not using a navigation controller between them all. I'd rather just have space and put my own button at the top. This will also fix the issue of messages going all the way to the status bar up.

How do I get space up at the top of a JSQVC to allow to user to back out? If I do have to use a Navigation Controller is it possible to just use navigation for a single view? enter image description here

user6820041
  • 1,213
  • 2
  • 13
  • 29

2 Answers2

0

First add a navigationController then push the JSQMessagesView onto that.

Dan Leonard
  • 3,325
  • 1
  • 20
  • 32
0

I previously had the same problem that you are having, to solve this I created a navigation bar programmatically. To do that you can create a function and call the function from viewDidLoad or viewDidAppear.

func addNavBar() {
        let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height:54)) // Offset by 20 pixels vertically to take the status bar into account

        navigationBar.barTintColor = UIColor.black
        navigationBar.tintColor = UIColor.white

        navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]

        // Create a navigation item with a title
        let navigationItem = UINavigationItem()
        navigationItem.title = "NavBarAppears!"

        // Create left and right button for navigation item
        let leftButton =  UIBarButtonItem(title: "Back", style:   .plain, target: self, action: #selector(btn_clicked(_:)))

        let rightButton = UIBarButtonItem(title: "Right", style: .plain, target: self, action: nil)

        // Create two buttons for the navigation item
        navigationItem.leftBarButtonItem = leftButton
        navigationItem.rightBarButtonItem = rightButton

        // Assign the navigation item to the navigation bar
        navigationBar.items = [navigationItem]

        // Make the navigation bar a subview of the current view controller
        self.view.addSubview(navigationBar)
    }

    func btn_clicked(_ sender: UIBarButtonItem) {
        // Do something
        performSegue(withIdentifier: "segueBackToHomeVC", sender: self)
    }
nviens
  • 427
  • 2
  • 4
  • 18