objective-c - 像 Twitter 的 Compose Button 一样的全局/持久 UIBarButtonItem?

标签 objective-c ios cocoa-touch uinavigationcontroller

我有一个带有很多 viewControllersUINavigationController,我想在右上角添加一个 UIBarButtonItem。我这样做了,但我必须对每个 View Controller 单独执行此操作。添加一次并在整个应用程序中保留它的最佳模式是什么?

最佳答案

是的,您可以像在 appDelegate 中一样创建一个全局函数,并在该函数上传递一些参数。比如传递你的 navigationController、target、selector。

这是示例代码片段。

- (UIBarbuttonItem *) rightBarButtonGlobal:(UINavigationItem*)navigationItem target:(id)target {
  //you can also pass nsstring for title and selector for you desired selector.
  //But as per your question I assume you want a application logo like button in navigation bar. If that is the case just pass navigationItem as parameter.Create your logo button and assign to navigationItem.
  //Allocate button here
  navigationItem.rightBarButtonItem = button;
  [button release];
}

关于objective-c - 像 Twitter 的 Compose Button 一样的全局/持久 UIBarButtonItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554733/

相关文章:

ios - 使用自定义布局的 UICollectionView 项目顺序

objective-c - Core Data 中用于 C 结构的 NSValueTransformer

objective-c - Good Dynamics如何保护NSURLConnection?

ios - ios 中的自动完成文本字段

iphone - 从XML源过滤UITableView

iphone - 推送通知的 APNS 端口号和主机名

ios - 使用 swift 和 spriteKit 如何围绕节点外部的点旋转 SKSpriteNode?

ios - 我的应用程序的屏幕截图显示空白的 YouTube 视频

ios - 如何在不通过 segue 实例化的情况下预加载或缓存目标 View Controller

ios - 在 Cocoa Touch Framework 中包装静态库