ftw*_*ere 4 iphone xcode uitabbarcontroller uinavigationcontroller
如何使用导航控制器中的按钮推送视图?我试着效仿这个例子:http: //www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/
这正是我需要的,我有一个UITabBarController4个标签,其中一个是UINavigationController.我想从第一个视图推送包含导航控制器的视图 - 这很简单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;
}
Run Code Online (Sandbox Code Playgroud)
这里也是连接的屏幕截图 http://imageshack.us/photo/my-images/847/screenshot20110719at620.png/
我已经尝试过你们建议但仍然没有,按钮(无论是创建Interface Builder还是编程)都表现得像是没有链接到任何方法.
把它放在你想要创建按钮的位置:(例如根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];
Run Code Online (Sandbox Code Playgroud)
并实现此方法:
- (void)didPressButton:(UIButton *)sender
{
UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
}
Run Code Online (Sandbox Code Playgroud)