开发者

Create a UIBarButtonSystemItem with UIBarButtonItemStyle

I want to create a system UIBarButton, but I want it to have plain style.

I've tried with this code, but the style is ignored. What's wrong with it?

UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];    
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightB开发者_开发知识库arButtonItem = search;
[search release];


The main thing here is that you need to place your button in the previous controller, not in the one that is going to be pushed.

//Your actual ViewController
UIBarButtonItem *search = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];    
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightBarButtonItem = search;
[search release];

//Controller that is going to be pushed and will display the new UIBarButtonItem
[self.navigationController pushViewController:newViewController animated:YES];


Found a similar thread here.

It seems that the way to go about making this plan is to create your custom UIButton and assign it to the bar button.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜