我正在将一个只是 TabViewContoller 的简单应用程序转换为需要通过 Navagation 控制器推送多个视图的应用程序。以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create Start view controller.
UITabBarController *rootController = [[UITabBarController alloc] init];
UINavigationController *startController = [[UINavigationController alloc] initWithRootViewController:rootController];
// Similarly create for TabBarController, ToDoController and any others over time ...
UIViewController *ToDoViewController = [[UIViewController alloc] initWithNibName:@"ToDoViewController" bundle:nil];
// Create an array of view controllers.
NSArray* controllers = [NSArray arrayWithObjects:startController, ToDoViewController, nil];
// Create our tab bar controller.
self.rootController = [[UITabBarController alloc] init];
// Set the view controllers of the tab bar controller.
self.rootController.viewControllers = controllers;
// Add the tab bar controller to the window.
[self.window addSubview:self.rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
运行时给我两个警告和崩溃。警告位于 UINavigationController 行和 NSArray 行上。在这两种情况下,我都会收到以下消息:
rootContoller 的本地声明隐藏了实例变量。
这是我的头文件:
#import <UIKit/UIKit.h>
@interface Wasted_TimeAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
UINavigationController *startController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
@property (nonatomic, retain) IBOutlet UINavigationController *startController;
@end
我确信这与我希望 UITabBarContoller 成为我在堆栈中的第一个视图控制器这一事实有关。有关设置此行为的正确方法的任何建议?