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

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

问题描述

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



<这正是我需要的,我有一个带有4个标签的 UITabBarController ,其中一个是 UINavigationController 。我想从第一个视图推送包含导航控制器的视图 - 这是一个简单的 UIView 。它不起作用,我尝试使用以编程方式创建的按钮,没有任何反应。任何指针?



这是我的代码

  @interface HomeViewController :UIViewController {

}

- (IBAction)pushViewController:(id)sender;

@end

---

#importHomeViewController.h
#importNewViewController.h

@implementation HomeViewController

- (IBAction)pushViewController:(id)sender {
NewViewController * controller = [[NewViewController alloc] initWithNibName:@NewViewControllerbundle:nil] ;
[[self navigationController] pushViewController:controller animated:YES];
[控制器发布],controller = nil;
}

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



我已经尝试过你们建议但仍然没有,按钮(是否在界面生成器中创建或以编程方式)表示它们没有链接到任何方法。

解决方案

将它放在你想要创建按钮的位置:(例如Root VC的 -viewDidLoad

  UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
button.frame = CGRectMake(100.0,100.0,100.0,40.0);
[button setTitle:@按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];
}


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/

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?

Here's the code I have

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

Here is also the screenshot with the connections http://imageshack.us/photo/my-images/847/screenshot20110719at620.png/

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.

解决方案

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

And implement this method:

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

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

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