views:

160

answers:

2

i am having an issue where when i call an IBaction from a certain viewcontroller the app crashes, but i can get the desired result elsewhere.

basically i have a navigationcontroller buried in a tab bar controller. if i call an IBActions from the first view of the navigationcontroller it works fine, but if i create a view with an initWithNib and push it on to the navcontroller stack and then try to call an IBAction on the instance of the viewcontroller i pushed on the stack the app crashes.

when the app first loads there is an "x" button in the menubar which pulls up an addressbook picker. this works fine. if you click on the "new" button in the menubar the propper view gets created and pushed on the stack. this new view has 1 button called "sellect bill to" which only has a log statement in the IBAction call but still causes a crash. the IBAction for the "select bill to" button is location in that views viewcontroller.

any help untangling this would be appreciated.

source can be found at http://www.swnsn.com/S4X.zip

A: 

Hi, I am just a beginner. So i might not be right in my suggestions.

A.

I checked the Debugger console and the following error is 'NSInvalidArgumentException', reason: '* -[UIViewController pickBillTo:]: unrecognized selector sent to instance 0x44487f0' I m not sure what the problem is.

B.

-(IBAction)pickBillTo:(id) selector{ // Your code

-(IBAction)pickBillTo:(id) sender{ // my suggestion

C.

You havent relseased memory for button, firstName, lastName, number

Anand

you can call it sender, selector, myVar. it's just how you access the selector inside of the method. didn't worry about releasing those vars yet, cause i haven't used them and got hung up on this problem. thanks for the response though.
swnsn
A: 

You're trying to send pickBillTo: to an instance of UIViewController, not your custom subclass.

In FirstViewController.m, change:

UIViewController *newView = [[UIViewController alloc] initWithNibName:@"NewOrderView" bundle:nil];

to:

NewOrderView *newView = [[NewOrderView alloc] initWithNibName:@"NewOrderView" bundle:nil];

You'll also have to import NewOrderView.h, and you should probably rename that class to NewOrderViewController, and name your variable newViewController, since it's a controller, not a view.

chrispix
Thank you so much!
swnsn