开发者

Getting an error when calling an IBAction from a button click inside a xib

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


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.


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 haven't released memory for button, firstName, lastName, number

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜