1
的RootViewController的
我想創建一個應用程序與導航控制器作爲窗口根視圖控制器和在導航控制器的標題視圖分段控制以切換其根視圖控制器的UINavigationController與UISegmentedControl在AppDelegate中切換的UINavigationController
問題:分段控制不將其添加到嘮叨控制器後本
代碼:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
FirstViewController * fc = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:fc];
[fc release];
self.window.rootViewController = nc;
NSArray * array = [NSArray arrayWithObjects:@"GPS",@"List",@"Map", nil];
UISegmentedControl * sc = [[UISegmentedControl alloc] initWithItems:array];
sc.frame = CGRectMake(0, 0, 250, 50);
sc.segmentedControlStyle = UISegmentedControlStylePlain;
[nc.navigationItem setTitleView:sc];
[sc release];
[nc release];
[self.window makeKeyAndVisible];
return YES;
}
嘗試將其添加到fc.navigationItem,然後您可能需要將此分段控制視圖添加到呈現的每個視圖控制器的所有導航項 – 2013-04-09 10:50:21