iphone - 如何在 tabbarcontroller 的特定 View 中添加右栏按钮项

标签 iphone ios xcode uinavigationcontroller uitabbarcontroller

作为我的标题,如何在 tabbarcontroller 的特定 View 中添加 rightbarbuttontiem ?

我正在使用 Storyboard来创建 tabarcontroller。

我尝试了此操作,但该项目未显示

   UIBarButtonItem *settingButton = [[UIBarButtonItem alloc]  
                                  initWithImage:[UIImage imageNamed:@"gear.png"]  
                                  style:UIBarButtonItemStylePlain  
                                  target:self  
                                  action:@selector(pushToSetting)];  

//BarButtonItem *settingButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = settingButton;

最佳答案

您使用导航 Controller 吗?如果是,那么您的代码应该可以工作。如果您仅使用 UINavigationBar,则必须设置 UINavigationBar 的 items 属性。由于您没有获得右键项目,我假设您正在使用 UINavigationBar。此代码应该有效:

UIBarButtonItem *settingButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:nil];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Test"];
navItem.rightBarButtonItem = settingButton;
NSArray *navItems = [NSArray arrayWithObject:navItem];
[self.navBar setItems:navItems];

您现在应该拥有右侧的栏按钮项。这里,navBar是一个UINavigationBar导出。您还可以使用以下方法将导航项弹出和推送到 UINavigationBar 上:

  • (void)pushNavigationItem:(UINavigationItem *)项目动画:(BOOL)动画;
  • (UINavigationItem *)popNavigationItemAnimated:(BOOL)动画;

关于iphone - 如何在 tabbarcontroller 的特定 View 中添加右栏按钮项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8243851/

相关文章:

ios - 在 UIScrollView 中滚动和缩放 UIImageView

iphone - twitpic 与 iPhone 应用程序集成

iphone - 哪个官方文档描述了必须包含在应用程序包中的图标和 iTunesArtwork?

ios - Assets 目录编译错误

xcode - 在现有项目中包含 INAppStoreWindow

ios - 获取从当前位置到达某个地方的时间

iphone - UITableView 上冲突的手势识别器

ios - 在不同的 View Controller 中打开webkit View

ios - 扩展和收缩 View 中相邻的 UI 对象

objective-c - 读取和写入图像到 SQLite DB 以供 iPhone 使用