3

I want to add Layer SDK to my application (using Swift).

All view controllers here are created programmatically. Therefore I can't segue to them. I have 4 tabs in my application (UITabBarController). One of them is chat. In the chat tab I created a segue to UINavigationController. Now I want to load conversationListViewController in this UINavigationController. For that I created a class for this UINavigationController i.e. ConversationListViewController and added the following code:

class ChatNavigationViewController: UINavigationController {
  var conversationListViewController: ConversationListViewController!
    var layerClient: LYRClient!
      override func viewDidLoad() {
        let appDelegate = UIApplication.sharedApplication().delegate as!AppDelegate
        self.layerClient = appDelegate.layerClient
        self.conversationListViewController = ConversationListViewController(layerClient: appDelegate.layerClient)
        self.conversationListViewController.displaysAvatarItem = true

        self.navigationController!.pushViewController(self.conversationListViewController, animated: true)
      }
}

But this is not working. And giving this kind of effect: the ConversationViewController is not loaded in UINavigationController. I am not sure if I am doing it the correct way. I'm searching for the correct way, but unable to find.

Screenshot

Learner
  • 5,192
  • 1
  • 24
  • 36
Nishant Dongare
  • 549
  • 3
  • 16
  • it's easy , create your view controller in storyBoard and embed it on UINavigationController , set the identfire for your navigation controller, then : set your root view controller as [[YourNavigationController viewControllers]firstObject] – Mo Farhand Nov 29 '15 at 06:43

2 Answers2

4

I Solved it. I dragged new NavigationViewController and added ConversationListViewController to rootviewController.I think i should try this first. Anyways thanks guys for your help.enter image description here

Nishant Dongare
  • 549
  • 3
  • 16
1

Because you want to do this programatically:

You need to manually initialize the controller before stacking it up on the Navigation Controller. Try this:

navigationController?.pushViewController(self.conversationListViewController.init(), animated: true)

Nisarg Shah
  • 109
  • 1
  • 5
  • var tempVC = ChatFriendsVC() self.navigationController!.pushViewController(tempVC.dynamicType.init(), animated: true) . Tried this but not getting the output. – Nishant Dongare Nov 29 '15 at 08:59
  • override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.deselectRowAtIndexPath(indexPath, animated: true) let vc = self.conversationListViewController.init() navigationController?.pushViewController(vc, animated: true) } – Nisarg Shah Nov 29 '15 at 09:08
  • But this is not extending `TableViewController`. – Nishant Dongare Nov 29 '15 at 09:11
  • What is the controller that you have put in the snapshot? Shouldn't that be a `TableViewController` ? – Nisarg Shah Nov 29 '15 at 09:46
  • This are the extra menus in my `TabBarController` :) – Nishant Dongare Nov 29 '15 at 09:48
  • A `TabBarController` should load a `TableViewController` which initializes and loads the `ViewController`. From the information provided in the question, it is difficult to suggest beyond this. – Nisarg Shah Nov 29 '15 at 10:50