【发布时间】:2014-04-03 02:17:23
【问题描述】:
我是iOS编程的新手,这个问题在某些人看来可能很愚蠢,对不起。 我这里有一个问题是我有一个现有的 UIViewController (A) 和另一个 UIViewController (B),我想向 A 添加一个 UINavigationController,这样当我按下 A 上的按钮时,我将被引导到 B。我试过了下面的方法,但它并没有解决问题:
在 AppDelegate 中:
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.tabbarController = [[UITabBarController alloc] init];
UIViewController *viewController_1 = [[WUSTLViewController_1 alloc] init];
UIViewController *viewController_2 = [[WUSTLViewController_2 alloc] init];
UIViewController *viewController_3 = [[WUSTLViewController_3 alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController: viewController_3];
self.tabbarController.viewControllers = [NSArray arrayWithObjects:viewController_1, viewController_2, navigationController, nil];
self.window.rootViewController = self.tabbarController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
在 WUSTLViewController_3.h (A) 中:
#import <UIKit/UIKit.h>
#import "WUSTLViewController_4.h"
@interface WUSTLViewController_3 : UIViewController {
WUSTLViewController_4 *viewController_4;
}
@property UINavigationController *navigationController;
@end
在 WUSTLViewController_3.m (A) 中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
viewController_4 = [[WUSTLViewController_4 alloc] init];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(80, 50, 150, 40);
[myButton setTitle:@"Push" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
}
- (IBAction)pressButton:(id)sender
{
[self.navigationController pushViewController:viewController_4 animated:YES];
}
当我点击按钮时,什么也没发生。
【问题讨论】:
标签: ios iphone objective-c uiviewcontroller uinavigationcontroller