开发者

UINavigationItem - unrecognized Selector

I am having two nib files a开发者_JAVA技巧nd from first nib file while tapping Add button on Navigation Bar i moved to another and on Second View I again have navigation bar with Save Button which i created in viewDidLoad Event as below:

btnAdd = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self.navigationItem action:@selector(saveRecord:)];
self.navigationItem.rightBarButtonItem = btnAdd;
self.navigationItem.title = @"Add Information";
[btnAdd release];

Also I have created the method saveRecord as below

-(IBAction) saveRecord: (id)sender
{
     NSLog(@"Save Button Tapped");
}

But after running the program following error comes saying that it cannot find saveRecord method.. Even this method is also not called with Breakpoints..

ERROR

2011-08-27 11:48:25.813 BarcodeDemo[1903:207] -[UINavigationItem saveRecord:]: unrecognized selector sent to instance 0x5558660
2011-08-27 11:48:25.817 BarcodeDemo[1903:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem saveRecord:]: unrecognized selector sent to instance 0x5558660'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x012f95a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0144d313 objc_exception_throw + 44
    2   CoreFoundation                      0x012fb0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x0126a966 ___forwarding___ + 966
    4   CoreFoundation                      0x0126a522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x003744fd -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x00586cc3 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
    7   UIKit                               0x003744fd -[UIApplication sendAction:to:from:forEvent:] + 119
    8   UIKit                               0x00404799 -[UIControl sendAction:to:forEvent:] + 67
    9   UIKit                               0x00406c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527

and some more stack goes on..........

Can any one help me ... what i am forgetting????????


Don't use target:self.navigationItem, or the saveRecord: method will be sent to the UINavigationItem (which is the error you're getting). You probably just want target:self.


target is the object in which the action is defined. The target should be self here, not self.navigationItem.

target:self


try this

UIBarButtonItem * btnAdd = [[UIBarButtonItem alloc] 
                                    initWithTitle:@"Add Information"  
                                    style:UIBarButtonItemStyleBordered
                                    target:self 
                                    action:@selector(saveRecord:)];
self.navigationItem.rightBarButtonItem = btnAdd;
[btnAdd release];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜