Nishant Dongare
Nishant Dongare

Reputation: 549

Set initial viewController in Navigation controller programmatically (Layer SDK)

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

Upvotes: 3

Views: 1095

Answers (2)

Nishant Dongare
Nishant Dongare

Reputation: 549

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

Upvotes: 4

Nisarg Shah
Nisarg Shah

Reputation: 109

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)

Upvotes: 1

Related Questions