1

viewDidLoad 内にあるカスタム UIBarButton を作成できるこのコードがあります。

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

ここで、UIBarButton が押されたときに以下のこのメソッドを呼び出して、次のビュー コントローラーへのセグエが実行されるようにします。

- (void) didPressDone {

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

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

私はこれについていくつかの調査を行いました。しかし、私が見たものはすべて、UIBarButton をオブジェクト ライブラリから ViewController にドラッグし、それを次の VC に接続するだけでした。私の場合はかなり違います。

アドバイスをください:)

4

2 に答える 2

2

ターゲットをselfに設定し、アクションをdidPressDoneセレクターに設定できます。

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

セレクターには、次のような署名が必要です。

- (void)didPressDone:(id)sender
于 2012-05-02T01:53:34.637 に答える