iphone - 使用 UIBarButtonItemStyle 创建一个 UIBarButtonSystemItem

标签 iphone ios uinavigationbar uibarbuttonitem uibarbuttonitemstyle

我想创建一个系统 UIBarButton,但我希望它具有简单的样式。
我试过这段代码,但样式被忽略了。 有什么问题吗?

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

最佳答案

这里最主要的是您需要将按钮放在前一个 Controller 中,而不是将要按下的 Controller 中。

//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];

关于iphone - 使用 UIBarButtonItemStyle 创建一个 UIBarButtonSystemItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7351202/

相关文章:

ios - 如何清除 swift4 中的导航栏颜色?

iOS:从导航栏中删除以编程方式添加的搜索栏

javascript - 由于 iOS 12.4 iframe 无法更改顶部 url

ios - “项目名称”是通过优化编译的——步进可能表现得很奇怪;变量可能不可用

iphone - 是否有适用于 iPhone 的 Wavefront OBJ 加载器的开源实现?

ios - Objective-C 解决函数重载

objective-c - 将一个 ActivityIndi​​cator 与两个类一起使用

UINavigationBar 背景图像 - 在 iOS 11 中损坏?

iphone - 试飞坠机报告

iphone - Float 不可转换为 CGFloat,CGFloat 不可转换为 Float