I am struggling to add a navigation bar to a JSQMessagesViewController. Is it possible to do this in interface builder or do I have to create the navigation bar programmatically?
When attempting to do this with IB, the navigation bar is not visible at runtime and the messages scroll all the way to the top of the iPhone display. I would think that constraints need to be added in order for this to work. I am not sure how or what to add the constraints to since there isn't anything other than my navigation bar in IB.
Sorry if this is a basic question, thanks for any guidance you can provide!
UPDATE: I am still curious if this can be done via IB. However, I have figured out how to do this programmatically. I added the following to viewDidLoad()
// Create the navigation bar
let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, self.view.frame.size.width, 64)) // Offset by 20 pixels vertically to take the status bar into account
navigationBar.backgroundColor = UIColor.whiteColor()
navigationBar.delegate = self;
// Create a navigation item with a title
let navigationItem = UINavigationItem()
navigationItem.title = contacts[i].firstName
// Create left and right button for navigation item
let leftButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "btn_clicked:")
let rightButton = UIBarButtonItem(title: "Details", style: UIBarButtonItemStyle.Plain, target: self, action: "details_clicked:")
// 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)
This seems to get the job done. Let me know if there is a better way to go about this.