2012-05-02 5 views
1

이 코드를 통해 viewDidLoad 내부에 사용자 정의 UIBarButton을 만들 수 있습니다.사용자 정의 UIBarButton을 사용하여 푸시 세그 수행

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                   style:UIBarButtonItemStyleDone 
                   target:nil 
                   action:nil]; 
    self.navigationItem.rightBarButtonItem = doneButton; 

지금, 나는 다음 뷰 컨트롤러에 SEGUE이 완료 될 수 있도록 UIBarButton을 누르면 아래에이 메소드가 호출하려는.

- (void) didPressDone { 

    PointsResultsViewController *pointsResults = [self.storyboard instantiateViewControllerWithIdentifier:@"resultsPointsVC"]; 

    [self.navigationController pushViewController:pointsResults animated:YES]; 
} 

나는 이에 관한 조사를 해왔다. 그러나 내가 본 것들은 UIBarButton을 객체 라이브러리에서 ViewController로 드래그하는 것뿐입니다. 다음 VC로 연결하고, prepareForSegue 메소드를 가지고 있습니다. 간단합니다. 제 경우에는 꽤 다릅니다.

- (void)didPressDone:(id)sender 

답변

2

당신은 자신의 목표와 didPressDone 선택에 작업을 설정할 수 있습니다 :)하십시오 어떻습니까?

1 단계 :

최대

와이어 : 당신의 Viewcontroller.h 파일에서

, 단지 this-

@property(nonatomic, strong) IBOutlet UIBarButton *doneButton; 

및 IT-

-(IBAction)didPressDone:(id)sender; 

2 단계에 대한 IBAction를 방법처럼 UIBarButton의 IOBOutlet를 만들 스토리 보드를 통해 UIBarButton을 만들고 액션 메소드를 첨부하십시오.

3 단계 :

이제

는의, 당신은 wanted- Viewcontroller.m 파일로 이동하여 -(void)viewDidLoad 방법에서는 UIBarButton에게 길을 초기화 할 수

self.doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                   style:UIBarButtonItemStyleDone 
                   target:nil 
                   action:nil]; 
    self.navigationItem.rightBarButtonItem = self.doneButton; 

방법 서명, 이외의 " didPressDone "메소드 구현은 동일합니다-

-(IBAction)didPressDone:(id)sender { 

    PointsResultsViewController *pointsResults = [self.storyboard instantiateViewControllerWithIdentifier:@"resultsPointsVC"]; 

    [self.navigationController pushViewController:pointsResults animated:YES]; 
} 

희망이 있습니다.

+0

괜찮음! 이 하나를 시도 할 것입니다 :) – Grauzten

+0

고마워! 너는 남자 야! :) – Grauzten

0

:

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                   style:UIBarButtonItemStyleDone 
                   target:self 
                   action:@selector(didPressDone:)]; 

가 선택기는이 같은 서명이 있어야합니다

조언

관련 문제