制作的UIButton充当navigationcontroller(Make UIButton ac

2019-07-31 07:07发布

我怎样才能让一个普通的UIButton充当navigationcontroller,这样,当它压我可以开辟一个新的看法?

Answer 1:

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

 }

我认为这将是对你有所帮助。



Answer 2:

假设你在你的项目中使用UINavigation控制器。

那么对于按键操作只需要调用

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

和被调用该方法只需做到以下几点:

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


文章来源: Make UIButton act as navigationcontroller