开发者

iPhone/iPad - issues with NavigationBar button?

I my application i have added button in NavigationBar like this..

UIBarButtonItem *more=[[UIBarButtonItem alloc] initWithImage:[UIImage imageN开发者_开发问答amed:@"search-25by25.png"] style:UIBarButtonItemStylePlain target:self action:@selector(SelectMission:)];

self.navigationItem.rightBarButtonItem = more;

When i am clicking on button application get's shutdown...

If i am doing same thing with normal button it's working fine can any one help me why it's behaving like this?


Try This

UIImage *i=[UIImage imageNamed:@"search-25by25.png"];

  UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
  myButton.bounds = CGRectMake( 0, 0, i.size.width, i.size.height );    
  [myButton setImage:i forState:UIControlStateNormal];
  [myButton addTarget:self action:@selector(SelectMission:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *more=[[UIBarButtonItem alloc] initWithCustomView:myButton]; self.navigationItem.rightBarButtonItem = more;

hope it helps :)


Have you looked in the code for SelectMission:? The code you've posted is only for presenting the button, which from your description appears to be working.

Also if there's anything being dumped into the console (Command-Shift-R)?


Judging by the crash log in your comment, I would say this has nothing to do with the UIBarButtonItem class in particular, and everything to do with your action handler. The crash logs tell the whole story: Your class does not implement a method called SelectMission: that takes one argument. Some caveats about the @selector keyword that you will want to double check:

1) Capitalization. Make sure that the method you implement is SelectMission:. Not selectMission:, selectmission:, Selectmission:, etc.

2) Arguments. The colon indicates that the method SelectMission: takes one argument. If you have implemented it and forgotten the argument it will crash with the exception you posted.

That should help narrow down the issue.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜