0

I am new to iOS, can any one please help me to open and activity on Button click.

I have tried below methods, but the app remains on same ViewController, i am using Singleview Application type

 Second *sec = [[Second alloc] init];
 [self.navigationController pushViewController:sec animated:YES];

 Second *sec = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondV"];
 [self.navigationController pushViewController:sec animated:YES];

can anyone please help me to solve this.

1
  • I strongly suggest you to go through documentation provided by Apple for getting some idea. Commented Dec 11, 2014 at 14:03

3 Answers 3

4

if you are using storyboard then Embed your viewcontroller to UINavigationController Editor->EmbedIn->NavigationController try this

Sign up to request clarification or add additional context in comments.

1 Comment

ok, faster way than mine @Sam ;-). Not using storyboard so much, learned something from you, too ;-).
3

If not using Storyboard, then following might help:

Second *sec = [[Second alloc] initWithNibName:@"Second" bundle:nil];
[self.navigationController pushViewController:sec animated:YES];

For Storyboard enabled code:

Second *sec = [self.storyboard instantiateViewControllerWithIdentifier:@"YourIdentifierForVC"];
[self.navigationController pushViewController:sec animated:YES];

BTW, I strongly suggest you to google the problem for solution & search SatckOverflow - first, before posting as a new question.

Also, you should reconsider the naming for the class. Just a suggestion.

1 Comment

Thank you for your Valuable comments
0

to push to another view controller you need to set a UINavigationController in front of your UIViewController in storyboard. Your self.navigationController might be nil, that's why it is not pushing your view controller.

Therefore drag and drop a Navigation Controller to your storyboard and delete the default TableViewController (make sure to click on empty space in storyboard before selecting and deleting it) and connect the UINavigationController to your own 'single view controller' by right-clicking on the yellow arrow and connecting the rootViewController outlet with it).

Then, select the UINavigationController on your storyboard and in Attributes Inspector (the fourth symbol in the right panel) under the section View Controller select Is Initial View Controller.

2 Comments

Whenever i use drag and drop Navigation Controller, it drops TableviewControler also. I do not have to work with TableView, I want to fire this code on Button Click
Yes. Then delete this tableViewController (select and press delete) and set your view controller as root view controller of the navigation controller (as described above, with right-clicking and connecting. Updated my answer accordingly).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.