1

我有一個很大的問題:在方法didSelectRowAtIndexPath我總是得到null self.navigationController.I有一個基於SplitViewController的項目,我想推動另一個視圖,當一個行被選中的細節TableView中。推從另一個視圖詳細查看

架構:

LoginView->SplitViewController->Master 
           ->Detail->AnotherView 

我AppDelegate.m:加載登錄表單

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

    // Initialize the app window 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    AuthentificationViewController *authentificationViewController =[[AuthentificationViewController alloc] initWithNibName:@"AuthentificationView" bundle:nil]; 
    self.window.rootViewController=authentificationViewController; 

    [authentificationViewController setModalTransitionStyle:UIModalTransitionStylePartialCurl]; 
    [self.splitViewController presentModalViewController:authentificationViewController animated:YES]; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

AppDelagate的內部接口我有那些特性:

@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController; 

@property (nonatomic, retain) IBOutlet UINavigationController *navController; 

方法手柄當我們點擊取消登錄表單上的取消按鈕

- (IBAction)btnCancel:(id)sender { 

    AppDelegate* app_delegate=[[UIApplication sharedApplication] delegate]; 
    //self.window = [[UIApplication sharedApplication] keyWindow]; 
    app_delegate.window.rootViewController= app_delegate.splitViewController; 

} 

當我們選擇了某行,我們有這個方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

     if([indexPath row] == 0) 
      { 

       // show add bookmark controller 

       BookmarkEditorController* bookmarkEditorController = [[[BookmarkEditorController alloc] initWithBookmark:[[ComputerBookmark alloc] initWithBaseDefaultParameters]] autorelease]; 

       [bookmarkEditorController setTitle:NSLocalizedString(@"Ajouter Connexion", @"Add Connection title")]; 
       [self.navigationController pushViewController:bookmarkEditorController animated:YES]; 

} 

但沒有什麼是發生在我選擇一行,navigationController是零取悅我怎麼能解決這個問題???

在此先感謝

編輯:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     UIViewController *localdetailViewController =nil; 
     if([indexPath row] == 0) 
     { 

      // show add bookmark controller 

      BookmarkEditorController* bookmarkEditorController = [[[BookmarkEditorController alloc] initWithBookmark:[[ComputerBookmark alloc] initWithBaseDefaultParameters]] autorelease]; 

      [bookmarkEditorController setTitle:NSLocalizedString(@"Ajouter Connexion", @"Add Connection title")]; 

      localdetailViewController=bookmarkEditorController; 
      AppDelegate *delegate =[[UIApplication sharedApplication] delegate]; 

      NSArray *viewControllers=[[NSArray alloc] initWithObjects: [delegate.splitViewController.viewControllers objectAtIndex:0],bookmarkEditorController,nil]; 
      delegate.splitViewController.viewControllers=viewControllers; 



     } 


} 

回答

1

看看這個Link

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
UIViewController* myVCToReplace = nil; 
    if(indexPath.row == 1) 
     myVCToReplace = [myVC1 alloc]init]; 
    else 
     myVCToReplace = [myVC2 alloc]init]; 

    NSMutableArray* array = [[NSMutableArray alloc] initWithArray:MySplitVC.viewControllers]; 
     [arr replaceObjectAtIndex:1 withObject:myReplacementVC]; 
     MySplitVC.viewControllers = arr; 
     [arr release]; 
+0

邦妮我按照鏈接,但我有同樣的錯誤「self.navigat ionController「爲空 – Pis

+0

哥們兒現在不必在主導航中推送視圖,你必須將splitviewContollers detailView設置爲導航控制器,並且現在將視圖推送到detailNavigation而不是self.navigation – Bonnie

+0

這是重要部分 UINavigationController * navController = [[UINavigationController alloc] init]; [navController pushViewController:localdetailViewController animated:YES]; TutorialSplitViewAppDelegate * delegate = [[UIApplication sharedApplication] delegate]; NSArray * viewControllers = [[NSArray alloc] initWithObjects:[delegate.splitViewController.viewControllers objectAtIndex:0],navController,nil]; delegate.splitViewController.viewControllers = viewControllers; – Bonnie