-1

I have created an app using storyboards. There are two view controllers first view or initial view is UnifeyeMobileViewController and the second view controller is called the SecondViewController. Both are connected through segue inside a navigation view controller. The SecondViewController has two buttons. On the IBAction of the first button inside secondViewController I am trying to run the below code.

I am trying to make use of the below code from the already existing app in previous version of xcode where we use to use XIB instead of storyboards but the below code does not work with storyboard it generates error msg in presentModelViewController statement.

UnifeyeMobileHelloWorld* unifeyeMobileViewController = [[UnifeyeMobileHelloWorld alloc] initWithNibName:@"UnifeyeMobileViewController" bundle:nil];
unifeyeMobileViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentModalViewController:unifeyeMobileViewController animated:YES];
[unifeyeMobileViewController release];

UnifeyeMobileHelloWorld is the viewcontroller that i am programmatically generating here. Imported UIController class from file->new->file->objective C class subclass of UIViewController.Named this file as UnifeyeMobileHelloWorld.And added the functionality in the implementation file.

Chris Trahey
  • 18,202
  • 1
  • 42
  • 55
strawberry
  • 49
  • 1
  • 7
  • What is the error from the debug console? – Chris Trahey Jul 13 '12 at 22:51
  • Also, did you import the xib file `UnifeyeMobileViewController`? – Chris Trahey Jul 13 '12 at 22:53
  • what is viewcontroller ? while using presentModalviewcontroller – Kunal Balani Jul 13 '12 at 23:06
  • @ctrahey: It generates error saying use of undeclared variable 'viewController',did you mean 'UIViewController'. And if a use the statement as [ self presentModelViewController:unifeyeMobileViewController animated:YES]; then my output consol reads: – strawberry Jul 13 '12 at 23:22
  • 2012-07-14 04:54:25.643 MyAr[949:10a03] -[SecondViewController btnHelloWorld:]: unrecognized selector sent to instance 0x7d3e9b0 2012-07-14 04:54:25.646 MyAr[949:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SecondViewController btnHelloWorld:]: unrecognized selector sent to instance 0x7d3e9b0' – strawberry Jul 13 '12 at 23:26
  • *** First throw call stack: (0x2012022 0x24a1cd6 0x2013cbd 0x1f78ed0 0x1f78cb2 0x2013e99 0x112414e 0x11240e6 0x11caade 0x11cafa7 0x11ca266 0x11493c0 0x11495e6 0x112fdc4 0x1123634 0x2a30ef5 0x1fe6195 0x1f4aff2 0x1f498da 0x1f48d84 0x1f48c9b 0x2a2f7d8 0x2a2f88a 0x1121626 0x20fd 0x2065) terminate called throwing an exception(lldb) – strawberry Jul 13 '12 at 23:26
  • That exception indicates that the button is trying to use an action method which your view controller (or whatever is set as the button's target) does not implement. What is the button hooked up to? – Chris Trahey Jul 13 '12 at 23:27
  • And no I did not import the XIB as I have imported the .h and .m files for the UnifeyaMobileViewController inside my app and then linked them to first view controller class under custom class coloum in interface builder – strawberry Jul 13 '12 at 23:29
  • @kunal: its the SecondViewController – strawberry Jul 13 '12 at 23:30

2 Answers2

0

So you are trying to create a modal segue from the second view controller to the first one? It would make more sense to just have one segue, a modal one from the first one (UnifeyeMobileHelloWorld) to the second one. Then when someone hits the button that you want to send them back, you can call

[self dismissModalViewControllerAnimated:YES]; //or no if you prefer

Not sure if this would fit with the rest of the design of your app, if you have more views after the second one, make it a push segue from UnifeyeMobileHelloWorld to the second one, and the Navigation Bar at the top will have a back button automatically.

jacerate
  • 456
  • 3
  • 8
  • That's not what the asker is trying to accomplish (unless I gravely misunderstand). Note that the "first" VC is `UnifeyeMobileViewController`, the second is `SecondViewController`, and the one we are trying to get to programmatically is `UnifeyeMobileHelloWorld` – Chris Trahey Jul 13 '12 at 23:30
  • ah sorry. please comment or post more detailed errors so i can help. perhaps a screenshot of your storyboard? – jacerate Jul 13 '12 at 23:34
  • @ctrahey: yes you are right that is what I am trying to do here Please advise – strawberry Jul 13 '12 at 23:44
0

edit: no action method:

The error you pasted in the comments above indicates that the issue is actually elsewhere. The button you are pressing is configured to send a message to SecondViewController with the selector: btnHelloWorld:, and SecondViewController does not have a method for that selector. This can happen if you rename a method and don't re-connect the button from the storyboard to the new method. So open up the storyboard, and re-ctrl-drag from the button to the appropriate action method in SecondViewController.

original answer:

It appears (via our conversation above), that you need to copy over the XIB file, or else move the content of the XIB to your storyboard and use more modern transition techniques (i.e. drag-and-drop segue transitions).

For a view controller to be used the way you are trying, it needs 3 files:

  1. the .h
  2. the .m
  3. the .xib (or .nib)

It would appear that #3 is missing in your case. It is needed in order to layout the ViewController's subviews and initialize their connections, and at the very least, it is needed because you are calling 'initWithNibName:`, which requires an *ib file

Chris Trahey
  • 18,202
  • 1
  • 42
  • 55
  • It says initWithNibName:@"UnifeyeMobileViewController" which is already there on the storyboard as the first view controller. – strawberry Jul 13 '12 at 23:38
  • UnifeyeMobileHelloWorld.h and UnifeyeMobileHelloWorld.m files are just files in my app with the code written for a viewcontroller so I am programmaticall linking on the UnifeyeMobileViewController.UnifeyeMobileHelloWorld* unifeyeMobileViewController = [[UnifeyeMobileHelloWorld alloc] initWithNibName:@"UnifeyeMobileViewController" bundle:nil]; – strawberry Jul 13 '12 at 23:41
  • It doesn't work like that. If there is a ViewController of that class in your storyboard, you cannot load it with alloc/initWithNibName, you need to load it with `[self.storyboard instantiateViewControllerWithIdentifier:@"someIDFromXcode"];` – Chris Trahey Jul 13 '12 at 23:47
  • But also note that the error indicated something else; see recent edit to this answer. – Chris Trahey Jul 13 '12 at 23:53