使UIButton充当navigationcontroller

我怎样才能使一个普通的UIButton作为一个导航控制器,以便当它被按下时,我可以打开一个新的视图?

按照以下方式在viewDidLoad方法中创buildyourButton …

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]; } 

我认为这对你有帮助。

假设您正在项目中使用UINavigation控制器。

然后为button动作只是打电话

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

对于被调用的方法只需执行以下操作:

 -(void)buttonAction{ [self.navigationController pushViewController:YourViewController animated:YES]; }