gpt4 book ai didi

iphone - 在 UINavigationController 中推送另一个 View ?

转载 作者:行者123 更新时间:2023-12-03 19:05:25 26 4
gpt4 key购买 nike

如何使用导航 Controller 中的按钮推送 View ?我尝试遵循这个例子: http://www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/

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

这是我的代码

@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 中创建的还是以编程方式创建的)就像没有链接到任何方法一样。

最佳答案

将其放在您要创建按钮的位置:(例如 Root VC 的 -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];
}

关于iphone - 在 UINavigationController 中推送另一个 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6749271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com