使UIButton充当导航控制器 [英] Make UIButton act as navigationcontroller

查看:70
本文介绍了使UIButton充当导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使常规UIButton充当导航控制器,以便在按下时我可以打开一个新视图?

How can I make a regular UIButton act as a navigationcontroller so that when it's pressed I can open up a new view?

推荐答案

按照以下方式在viewDidLoad方法中创建yourButton ...

Create yourButton in viewDidLoad method as following way...

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文件中声明.....

This is your method code and createViewController which is object of CreateViewController class and it is declared in .h file.....

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

            }


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

 }

我认为这会对你有帮助。

I think it will be helpful to you.

这篇关于使UIButton充当导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆