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 回答