0

通常の UIButton をナビゲーションコントローラーとして機能させて、押されたときに新しいビューを開くことができるようにするにはどうすればよいですか?

4

2 に答える 2

0

プロジェクトでUINavigationコントローラーを使用していると仮定します。

次に、ボタンアクションについては、

[yourUIButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

呼び出されるメソッドについては、次のようにします。

-(void)buttonAction{
    [self.navigationController pushViewController:YourViewController animated:YES];
}
于 2012-08-31T10:49:46.120 に答える
0

次のように、viewDidLoadメソッドでyourButtonを作成します...

UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[yourButton setTitle:@"YearButton" forState:UIControlStateNormal];
yourButton.frame = CGRectMake(240, 40, 75, 30);     
[yourButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside]; 
[self.view addSubview:yourButton];

これはメソッドコードであり、CreateViewControllerクラスのオブジェクトであるcreateViewControllerであり、.hファイルで宣言されています。

-(void) buttonSelected:(id)sender{
   if (!createViewController) {
                createViewController = [[CreateViewController alloc] initWithNibName:@"CreateViewController" bundle:nil];

            }


            [self.navigationController pushViewController:createViewController animated:YES];

 }

お役に立てればと思います。

于 2012-08-31T10:50:09.737 に答える