我正在学习Xcode并为IOS开发人员作为实习生工作。我正在使用Xcode 4.2和Lion OS。我的目标操作系统将是ios 3+版本。有人告诉我,使用故事板会给旧版本带来问题。所以我想开发而不使用Storyboard for navigationController。帮助我,因为所有旧的教程都没有帮助,因为xcode版本的变化导致很多错配。 请帮帮我。
答案 0 :(得分:3)
要创建导航控制器,请为项目模板选择单一视图应用程序。在AppDelegate.h中,创建UINavigationController的实例。在AppDelegate.m文件中,执行以下操作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
navigationController = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)viewController];
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
这将使基地成为导航控制器。您可以使用
添加其他视图[self.navigationController pushViewController:newViewController animated:YES];
答案 1 :(得分:0)
创建新项目时
有使用故事板的复选标记只是将其从那里移除。然后在你移动之前向前移动。
答案 2 :(得分:0)
将此添加到您的AppDelegate,并使用它们。看看会发生什么,你将学习。
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>{
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
//*****************************************//
.m file
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[Categories alloc] initWithNibName:@"Categories" bundle:nil];
UIViewController *viewController2 = [[Coupons alloc] initWithNibName:@"Coupons" bundle:nil];
UIViewController *viewController3 = [[Favourites alloc] initWithNibName:@"Favourites" bundle:nil];
UIViewController *viewController4 = [[AroundMe alloc] initWithNibName:@"AroundMe" bundle:nil];
viewController2.title = NSLocalizedString(@"Coupons", @"Coupons");
viewController2.tabBarItem.image = [UIImage imageNamed:@"coupons.png"];
viewController3.title = NSLocalizedString(@"Favourites", @"Favourites");
viewController3.tabBarItem.image = [UIImage imageNamed:@"favourites.png"];
// UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1,navController2, navController3, navController4, nil];
self.window.rootViewController = self.tabBarController;