在 UINavigationController 中推送另一个视图? [英] Push another View in UINavigationController?

查看:12
本文介绍了在 UINavigationController 中推送另一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用导航控制器中的按钮推送视图?我试着按照这个例子:http://www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/

How to push a view using a button in a navigation controller? I tried to follow this example: http://www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/

这正是我需要的,我有一个带有 4 个选项卡的 UITabBarController,其中一个是 UINavigationController.我想从第一个视图推送包含导航控制器的视图 - 这是一个简单的 UIView.它不起作用,我也尝试使用以编程方式创建的按钮,但没有任何反应.有什么指点吗?

This is exactly what I need, I have an UITabBarController with 4 tabs and one of them is an UINavigationController. I want to push that view containing the navigation controller from the first view- which is a simple UIView. It doesn't work, I tried also with a programmatically created button and nothing happens. Any pointers?

这是我的代码

@interface HomeViewController : UIViewController {

}

-(IBAction)pushViewController:(id)sender;

@end

---

#import "HomeViewController.h"
#import "NewViewController.h"

@implementation HomeViewController

-(IBAction)pushViewController:(id)sender {
        NewViewController *controller = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
    [[self navigationController] pushViewController:controller animated:YES];
    [controller release], controller = nil;
}

这也是连接的屏幕截图http://imageshack.us/photo/my-images/847/screenshot20110719at620.png/

我已经尝试了你们的建议,但仍然没有,按钮(无论是在 Interface Builder 中创建还是以编程方式创建)就像它们没有链接到任何方法一样.

I've tried what you guys suggested and still nothing, the buttons( whether they are created in Interface Builder or programmatically ) act like they're not linked to any method.

推荐答案

把这个放在你想创建按钮的地方:(例如Root VC的-viewDidLoad)

Put this where you want to create the button: (e.g. the Root VC's -viewDidLoad)

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100.0, 100.0, 100.0, 40.0);
[button setTitle:@"Press" forState:UIControlStateNormal];
[viewController.view addSubview:button];

[button addTarget:self action:@selector(didPressButton:) forControlEvents:UIControlEventTouchUpInside];

并实现这个方法:

- (void)didPressButton:(UIButton *)sender
{
    UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
    [self.navigationController pushViewController:viewController animated:YES];
}

这篇关于在 UINavigationController 中推送另一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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