简体   繁体   中英

Invalid argument exception - Navigation bar, tab bar, UIView

Class 1 has the following code that generates the exception -

-(IBAction) searchAllAction: (id) sender {
AddDiagSearchController *search = [[AddDiagSearchController alloc] initWithNibName:@"DiagSearch" bundle:nil];
[self.navigationController pushViewController:search animated:YES];
}

the pushViewController part generates the following exception - 2010-04-14 14:03:31.060 Nav[10314:207] *** -[UIView addTarget:action:forControlEvents:]: unrecognized selector sent to instance 0x3956a80

And the class I'm trying to push has the following code. All the connections for IBOutlets were made through the interface builder. It's has a tableView, search text bar and a tabbar at the bottom and I'll be adding this to a UINavigationController.

@interface AddDiagSearchController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
UIBarButtonItem *quickAdd;
UIBarButtonItem *searchAll;
UITextField *searchTxt;
}

@property (nonatomic, retain) IBOutlet UITextField *searchTxt;
-(IBAction) searchAllClicked:(id) sender;
-(IBAction) quickAddClicked:(id) sender;
-(IBAction) searchBtnClicked;
-(IBAction) resignResponder: (id) sender;
@end

That's not an invalid argument exception, it's unrecognized selector. You are sending a message meant for a UIControl to a UIView when pushing your AddDiagSearchController, which implies that you probably have a messed up nib file.

I'm not sure but it looks like memory-management issue. I found this article on CocoaDev useful in debugging such issues. Note that MallocStackLogging works only on simulator. I would bet that there is issue with previous view or controller (it is released too early), not with pushed one.

By the way it seems that you leak memory for search as you create and don't release nor autorelease it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM