boopathi
boopathi

Reputation: 137

Storyboard - navigation controller in viewcontroller

I am new to storyboard, in my story board i have a button over the view controller. On click of the button i am trying to add navigation controllers view as a subview it is getting added but when i try to push using the navigation controller the app is crashing. Please help me to fix this issue. I have uploaded the source code please download it from the  following Url

http://www.darrr.com/skyparts/test.zip

Upvotes: 0

Views: 2313

Answers (1)

Oleksandr Cheboraka
Oleksandr Cheboraka

Reputation: 56

The great advantage of storyboard is that much work can be done in Interface Builder. So to make your code work you should do next:

  1. Open your storyboard and make the following changes:
    1. Click right button on "viewCtrl" button and in a pop-up menu delete reference to the method -(IBAction)bttnTapped:(id)sender. Instead of calling action method on the button touch you should add a segue by ctrl-dragging from "viewCtrl" button to Navigation Controller and choose "Modal" type of segue.
    2. Select Navigation Controller and open an Attributes inspector. Then in the field "Top Bar" select Navigation Bar.
    3. In "Ctrl1" view click right button on "ctrl1" button and in the pop-up menu delete reference to the method -(IBAction)bttnTapped:(id)sender.
    4. Add View Controller from an object library to the storyboard. Then in Identity inspector's "Class" field type "ctrl2". After that ctrl-drag from "ctrl1" button to "Ctrl2" controller view and choose "Push" type of segue.

The view of your storyboard in Interface Builder should look like this: storyboard view

2.Go to ViewController.h and .m and delete the method - (IBAction)bttnTapped:(id)sender.

3.Go to ctrl1.h and .m and delete the method - (IBAction)bttnTapped:(id)sender.

The code should work. But I recommend to put methods - (void)viewDidLoad and - (void)viewDidUnload to ctrl1.m back.

If you want to run some code when the button was touched but before the view is loaded you should override the method - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender.

Upvotes: 1

Related Questions