0

ナビゲーション バーの左側に情報ボタンを作成しました。情報ボタンをクリックした後、ユーザーが「AboutViewController」という名前の別のビューに移動できるようにするにはどうすればよいですか? 助けてください!!(以下は私のコードです)

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(viewWillAppear:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[self.navigationItem setLeftBarButtonItem:modalButton animated:YES];
[modalButton release];
4

2 に答える 2

0

@selector最初に、この場合のように、メソッドを別の適切な名前に変更することをお伝えしたいと思いますnavigateToAboutView:。コードで指定したメソッド名が、呼び出し元のビューと同じビューに存在する可能性があるためです。

次に、カスタムメソッドで次のコードを記述します-

- (void) navigateToAboutView:(id)sender
{
    AboutViewController *aboutViewCntrl =[[AboutViewController alloc]initWithNibName:@"AboutViewController" bundle:nil];
    [self.navigationController pushViewController:aboutViewCntrl animated:YES];
}
于 2012-08-13T10:07:41.983 に答える
0

ボタンにターゲットを追加するときにセレクターとして渡された理由はわかりませんviewWillAppear:が、そのセレクターは、ボタンがタップされたときに呼び出されるメソッドを定義します。viewWillAppear:ビューが表示されるたびに呼び出されるメソッドであるため、ボタンをタップしたときに呼び出すのは意味がありません。したがって、次のようなものに変更して、次のようなopenAnotherViewメソッドを作成します。

- (void)openAnotherView {
    // Instantiate the view controller.
    AboutViewController *aboutViewController = [[AboutViewController alloc] init]; // or initWithNibName:bundle: if you use Interface Builder.

    // Present the view controller modally.
    [self presentModalViewController:aboutViewController animated:YES]
}

アバウトビューコントローラを閉じたい場合は、次の行を使用してAboutViewControllerください。

[self dismissModalViewControllerAnimated:YES]
于 2012-08-13T10:08:28.590 に答える