2013-03-01 79 views
0

我想補充兩個按鈕兩個導航欄右側一個用於設置和一個用於登錄,但問題是,只有一個按鈕,我已搜查來自於正確的,是編輯的還有其他方式可以讓我們製作兩個按鈕並給他們想要的標題。如何使導航按鈕,登錄和設置標題

+0

檢查此鏈接http://stackoverflow.com/questions/13985839/multiple-barbutton-in-navigation-bar-not-showing-on-ios6?rq=1我希望這將是對你有幫助。在此代碼 – jamil 2013-03-01 11:19:52

回答

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]; 
+0

很多錯誤??????? – 2013-03-01 11:05:26

+0

什麼錯誤 – 2013-03-01 11:28:25

+0

很多錯誤os語法和未知字符 – 2013-03-01 11:32:49

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

} 

現在這裏有兩個按鈕metthods點擊

-(IBAction)backTo:(id)sender{ 

    [self.navigationController popViewControllerAnimated:YES];  
} 

-(void) signInUser{ 

    //handle your sigin logic here 
} 

請!讓我,如果你需要更多的幫助!

+0

我可以這樣做,但我希望在同一側右側 – 2013-03-01 11:14:58

+0

你可以添加該按鈕代碼請 – 2013-03-01 11:43:16

+0

@ShakeelAhmed因爲我們需要添加按鈕陣列,請參閱更新的答案PL – swiftBoy 2013-03-01 11:43:23