rightBarButtonItem不在View上显示

时间:2014-10-07 03:08:16

标签: ios uinavigationbar uinavigationitem

我尝试使用以下代码以编程方式在视图中实现title和rightBarButtonItem,但标题和按钮未显示,其他所有内容(包括navigationBar和tabBarItem属性)都有效。无法弄清楚我哪里出错了。

- (void)viewDidLoad {
  [super viewDidLoad];

  self.navigationController.navigationBar.barTintColor = COLOR_NAVBAR_BACKGROUND;
  self.navigationController.navigationBar.tintColor = COLOR_NAVBAR_BUTTON;
  self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:COLOR_NAVBAR_TITLE};
  self.navigationController.navigationBar.translucent = NO;

  self.tabBarItem.title = nil;
  [self.tabBarItem setImage:[UIImage imageNamed:@"tab_group"]];
  [self.tabBarItem setSelectedImage:[UIImage imageNamed:@"tab_group"]];
  self.tabBarItem.title = @"Group";

  self.title = @"Group";

  self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStylePlain target:self action:@selector(actionNew)];
}

1 个答案:

答案 0 :(得分:3)

检查并尝试

 - (void)viewDidLoad
{
    [super viewDidLoad];



    UIBarButtonItem *rigthButtonClicked=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rigthButtonClicked:)];

     [self.navigationItem setRightBarButtonItem:rigthButtonClicked];


     UIBarButtonItem *leftButtonClicked=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(leftButtonClicked:)];

 [self.navigationItem setRightBarButtonItem:leftButtonClicked];
}

这里有两个按钮

-(void)rigthButtonClicked:(UIBarButtonItem *)button
{

    NSLog(@"RigthButtonClicked");
}

-(void)leftButtonClicked:(UIBarButtonItem *)button
{


    NSLog(@"leftButtonClicked");
}