View Full Version : Exception with setViewController

Apr 29, 2009, 02:05 AM
i try for 3 days, to change my viewController added into the MainWindow, with another viewController, i've already done that before, and it work very well.
Whereas, for the app I try to make now, when i push the button to change the view, it doesn't work, and my application send me an exception :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString setViewController:]: unrecognized selector sent to instance 0x7160'

Do you know what can cause this error ?
Thank youuu

North Bronson
Apr 29, 2009, 02:12 AM
Are these view controllers part of a navigation controller?

Do you have an instance variable named viewController?

Does that instance variable have a setter named setViewController: ?

Apr 29, 2009, 02:15 AM
my application is a simple Window Base Application (no naviguation bar or other), I want to swith my View with a simple UIButton.

I have a viewController instance on my myApplicationAppDelegate ..
And i don't have created a setViewController methodS...:s

North Bronson
Apr 29, 2009, 02:39 AM
Well, the UIButton is going to be part of a view, so you are going to switch *that* view to something else (another button in the new view)?

What kind of a switch are you talking about? Animation? You might want to just use a navigation controller.

Apr 29, 2009, 07:06 AM
Yes my switch is an animation, and, i've a view, which has a UIButton, and when i touch it, a new view appear

Apr 29, 2009, 07:39 AM
view != view controller

If you want to change views, make a new view (rather than a new view controller), and add that view to the current view controller.

If you want to change view controllers, you need to use a navigation controller or tab bar controller.

Apr 29, 2009, 07:54 AM
Usualy, i change my ViewController, without Naviguation Bar or Other, i don't know if it's the best way .... but it works. ..
It's just for this project, it doesn't work and i don't know why...
Even if in my First ViewController, I create a view same than the View of my Second ViewController, i've se same error...

Apr 29, 2009, 08:02 AM
i'm just realizing on,e thing: me app is a game, when, during the game, i ask for a new Game, i removeFromSuperView of my delegate.window the current view, i create a new instance of myGameViewController, and add the View of this of my window...first point: it works.

Seconde point, the bad one: when i'm on the menuViewController, and i want to change my viewController, i use the same peace of code, and i've the exception.... wird. ..

Apr 29, 2009, 08:04 AM
Magic: IT'S WORK :) thank you for your help, copy past my own code ... and it's work...lame