0

右側に2つのボタン2つのナビゲーションバーを追加したいのですが、1つは設定用、もう1つはログイン用ですが、問題は、検索した1つのボタンだけが右側に表示されることです。彼らはタイトルを望んだ。

4

2 に答える 2

0
UIBarButtonItem *addAttachButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAttachmentClicked:)];
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:LS(@"Send") style:UIBarButtonItemStyleBordered target:self action:@selector(sendClicked:)];
self.navigationItem.rightBarButtonItems = @[addAttachButton,sendButton];
于 2013-03-01T10:57:36.660 に答える
0

これは、私の UIViewController の実装ファイル (.m ファイル) で使用しているコードです。

 -(void)viewDidLoad{

  [super viewDidLoad];

  //back button
  UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:@" Back " style:UIBarButtonItemStyleBordered target:self action:@selector(backTo:)];    


  //Optional: if you want to add space between the back & login buttons
  UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace  target:nil action:nil];
           fixedSpaceBarButtonItem.width = 12;

  //login button
  UIBarButtonItem *signIn_BarButton = [[UIBarButtonItem alloc]initWithTitle:@" SIGN IN " style:UIBarButtonItemStyleBordered target:self action:@selector(signInUser)];            

  //add all buttons to right side
  self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:backButton, fixedSpaceBarButtonItem,signIn_BarButton, nil];

}

両方のボタンクリックの方法は次のとおりです

-(IBAction)backTo:(id)sender{

    [self.navigationController popViewControllerAnimated:YES];    
}

-(void) signInUser{

    //handle your sigin logic here
}

お願いします!さらに助けが必要な場合は、私に任せてください!

于 2013-03-01T11:11:36.870 に答える