2014-09-11 3 views

답변

3
UIBarButtonItem *yourButton = [[UIBarButtonItem alloc] 
           initWithTitle:@"Your Button"           
           style:UIBarButtonItemStyleBordered 
           target:self 
           action:@selector(methodName:)]; 
self.navigationItem.rightBarButtonItem = yourButton; 
[yourButton release]; 

그리고 그 방법은

-(IBAction)methodName { 
    // your code here 
} 
0

대신있는 UIButton의 바 NAV 대비 UIBarButtonItem을 추가해야합니다. T는 당신이 호출 할 수있는 수행

UIBarButtonItem *button = [[UIBarButtonItem alloc] 
           initWithTitle:@"Title"            
           style:UIBarButtonItemStyleBordered 
           target:nil 
           action:nil]; 
self.navigationItem.rightBarButtonItem = button; 
+0

@gerg 스토리 보드가 아닌 xib을 사용하고 있습니다. – Mowi

+0

두 가지 모두 사용할 수 있습니다. 문제가되지 않습니다. 어쩌면 네비게이션 바에서 콘센트를 만들어야 할거야. 왜 xib을 사용한다면이 버튼을 프로그램 적으로 추가하고 싶습니까? 당신은 IB에서 그것을 할 수 있습니다. – Greg

0
UIBarButtonItem *customBtn=[[UIBarButtonItem alloc] initWithTitle:@"Custom" style:UIBarButtonItemStylePlain target:self action:@selector(customBtnPressed)]; 
    [self.navigationItem setRightBarButtonItem:customBtn]; 

/////있는 UIButton이 당신이 정말로 원하는 경우 이벤트

-(IBAction)customBtnPressed:(id)sender 
{ 
    //Your code here 
} 
0

불리는이 시도.

UIButton *btnSample = [[UIButton alloc] initWithFrame:btnFrame]; 
    btnSample.backgroundColor = [UIColor blueColor]; 

    UIBarButtonItem *barBtn_cart = [[UIBarButtonItem alloc] initWithCustomView:btnSample]; 

    self.navigationItem.rightBarButtonItem = btnSample; 
관련 문제