2012-03-09 64 views
0

我想使用pushViewController和UIsegmentedController推送到其他視圖和xib。 我可以在xcode 4中做到嗎???如果可以的話,你能指導我嗎?我可以在UISegmentedControl中使用pushViewController嗎?

下面是一些代碼,我try.But將無法正常工作。

-(IBAction) segmentedControlIndexChanged:(id)sender 
{ 

    if ([sender selectedSegmentIndex] == 0) 
    { 
     BDshelveController *shelve_page = [[BDshelveController alloc] initWithNibName: @"BDshelveController" bundle:nil]; 

    } 
    else if([sender selectedSegmentIndex] == 2) 
    { 

     BDlibraryController *lib_page = [[BDlibraryController alloc] initWithNibName:@"BDlibraryController" bundle:nil]; 
     [self.navigationController pushViewController:lib_page animated:YES]; 
    } 

} 
+0

**究竟是如何**它不起作用? – Vladimir 2012-03-09 07:56:17

+0

它沒有推到BDlibraryController視圖:( – crazyoxygen 2012-03-09 08:01:06

回答

0

當然可以,這是你的東西可以檢查

  • 您在代碼中錯過segmentedIndex = 1。

  • 你錯過了選片段時,將調用pushViewController = 0

  • 或者,它更可能是self.NavigatonController是零

  • 你分段控制尚未連接valuechange到你的動作

如果self.navigationController是零,它取決於你如何初始化你的應用程序,如果你的應用程序是導航欄驅動的,那麼你的AppDelegate中的這段代碼應該解析iss ue:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourRootViewController]; // <-- depends if you have storyboards, xib etc...you should this already initialized 
    [self.window addSubview:navController.view]; 
    [navController release]; // <-- depends if you have ARC 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

否則我想你可以通過給自己作爲根控制器來初始化它在哪裏。

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self]; 
+0

我沒有複製所有code.sry的。現在我知道self.NavigationController是(null)。我應該編碼UINavigationController * navigationController = [[UINavigationController alloc] init ];第一?? – crazyoxygen 2012-03-09 09:21:57

相關問題