2012-12-02 5 views

답변

6

네비게이션 바에 추가 했으므로 약간 다르지만 기본적으로 같습니다. 단추를 만드는 동시에 리스너/처리기를 추가합니다. 여기에 내가 사용하여 탐색 모음에 <<>>을 추가 한 다음 다음

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@">>" style:UIBarButtonItemStylePlain target:self action:@selector(navNextButtonPressed)]; 
UIBarButtonItem *prevButton = [[UIBarButtonItem alloc] initWithTitle:@"<<" style:UIBarButtonItemStylePlain target:self action:@selector(navPrevButtonPressed)]; 
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:nextButton, prevButton, nil]; 

정상적으로 당신의 핸들러를 생성 : 그것은 UIControl의 서브 클래스 그것은 iOS..So위한거야

#pragma mark - button handling 
-(void)navNextButtonPressed 
{  
    NSLog(@"Next pressed"); 
} 

-(void)navPrevButtonPressed 
{ 
    NSLog(@"Prev pressed"); 
} 
+0

좋은 설명 감사합니다! – Tahlil

16

UIButton은 UIControl의 하위 클래스입니다.

단추를 만든 후에해야 할 일은 단추의 대상과 동작을 설정하는 것입니다. 즉

// Create your button: 
UIButton *button = // However you create your button 

// Set the target, action and event for the button 
[button addTarget:// the object that implements the action method, or nil if you want it to propagate up the responder chain. 
      action:// A selector for the method 
forControlEvents:UIControlEventTouchUpInside]; 
+2

인가를? ? 권리? –

관련 문제