我在 appDelegate 中设置了 navigationController,但现在我在另一个 ViewController 中回忆它,它不起作用。这是我的代码:
在 appDelegate.h
#import <UIKit/UIKit.h>
@class RootViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) RootViewController *viewController;
@property (strong, nonatomic) UINavigationController * navigationController;
@end
在 appDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
RootViewController * rootMenu;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
rootMenu = [[RootViewController alloc] initWithNibName:@"RootViewController_iPhone" bundle:nil];
} else {
rootMenu = [[RootViewController alloc] initWithNibName:@"RootViewController_iPad" bundle:nil];
}
self.viewController = rootMenu;
self.navigationController =[[UINavigationController alloc]initWithRootViewController:rootMenu];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
在 rootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController <UIGestureRecognizerDelegate>{
}
@property (nonatomic, retain) UIImageView * bigImageView;
@property (nonatomic, assign)BOOL fromRootViewController;
- (void)handleTap:(UITapGestureRecognizer *)recognizer;
@end
在 RootViewController.m
- (void)handleTap:(UITapGestureRecognizer *)recognizer{
if (recognizer.state == UIGestureRecognizerStateEnded) {
MenuViewController * menu = [[MenuViewController alloc]initWithNibName:@"MenuViewController" bundle:nil];
self.fromRootViewController = YES;
[self.navigationController pushViewController:menu animated:YES];
}
}
提前致谢