Ios 使UIButton充当navigationcontroller
如何使常规UIButton充当导航控制器,以便按下它时可以打开新视图?假设您在项目中使用UINavigation控制器 然后,对于按钮操作,只需调用Ios 使UIButton充当navigationcontroller,ios,uinavigationcontroller,uibutton,Ios,Uinavigationcontroller,Uibutton,如何使常规UIButton充当导航控制器,以便按下它时可以打开新视图?假设您在项目中使用UINavigation控制器 然后,对于按钮操作,只需调用 [yourUIButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 对于调用的方法,只需执行以下操作: -(void)buttonAction{ [self.navigationControl
[yourUIButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
对于调用的方法,只需执行以下操作:
-(void)buttonAction{
[self.navigationController pushViewController:YourViewController animated:YES];
}
按以下方式在viewDidLoad方法中创建您的按钮
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];
}
我想这会对你有帮助。你为什么要创建一个维吾尔布托教派?