开发者

Pressing UIBarButtonItem on a NavigationController

开发者 https://www.devze.com 2023-01-03 07:51 出处:网络
I\'ve added a button the my navigation bar like so: UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@\"Edit\" style:UIBarButtonItemStylePlain target:self action:@selector(meth

I've added a button the my navigation bar like so:

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(methodtocall:)];          

self.navigationI开发者_如何学JAVAtem.rightBarButtonItem = anotherButton;
[anotherButton release];

However when I press this I get a InvalidArgumentException. This is in a brand new navigation project. Does anyone know why I get this behaviour?


You need to define your action method like this:

-(void) methodtocall:(UIBarButtonItem *) sender {
   //do stuff...
}

You are probably getting an InvalidArgument error because you didn't define your method to receive the UIBarButtonItem.

0

精彩评论

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