2

編輯:添加源項目splitViewController配有兩張NavigationController連接協議

--> I uploaded a sample project that clearly shows my dilemma which can be found here <--

我創建了一個基於視圖的拆分中的應用。然後我在MainWindow.xib中的DetailViewController中添加了第二個UINavigationController。

然後,當點擊一個工具欄項時,彈出一個新的UIViewController子類。我用下面的代碼來進行流行:

DocumentDetailVC *DetailViewController = [[DocumentDetailVC alloc] initWithNibName:@"DocumentDetailVC" bundle:[NSBundle mainBundle]]; 
[detailViewController.detailNavController pushViewController:DetailViewController animated:YES]; 

DocumentsVC *RRequestViewController = [[DocumentsVC alloc] initWithNibName:@"DocumentsVC" bundle:[NSBundle mainBundle]]; 
[self.navigationController pushViewController:RRequestViewController animated:YES]; 

這是有效的。我遇到的問題是如何將信息或函數調用從Split View的Main一側傳遞到Split視圖的Detail一側?

如果通過以下方法呈現的UIViewController:

DocumentDetailVC *RRequestViewController = [[DocumentDetailVC alloc] initWithNibName:@"DocumentDetailVC" bundle:[NSBundle mainBundle]]; 
RRequestViewController.delegate=self; 
RRequestViewController.modalPresentationStyle = UIModalPresentationCurrentContext; 
[RRequestViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
[self presentModalViewController:RRequestViewController animated:YES]; 
[RRequestViewController release]; 
RRequestViewController = nil; 

我能夠通過協議來完成達到回如預期。

DocumentDetailVC,通過pushViewController加載時,層次結構如下:

NSLog([NSString stringWithFormat:@"%@",self]); 
//self = <DocumentDetailVC: 0x4e0d960> 
NSLog([NSString stringWithFormat:@"%@",self.parentViewController]); 
//self.parentViewController = <UINavigationController: 0x4e0ce30> 
NSLog([NSString stringWithFormat:@"%@",self.parentViewController.parentViewController]); 
//self.parentViewController.parentViewController = <UISplitViewController: 0x4e0d0f0> 

謝謝您的幫助。這個問題正在消耗我的生活!

--> I uploaded a sample project that clearly shows my dilemma which can be found here <--

回答

4

好吧,我知道我很遲到的答案,但這個答案是,我認爲,完善和工作。嘗試一下。打開RootViewController.h,在上面寫着這樣一行:

#import "Left.h" 
#import "Right.h" 

在@interface RootViewController的寫這行

Left *lefty; 
Right *righty; 
該申報財產後

@property (nonatomic, retain) Left *lefty; 
@property (nonatomic, retain) Right *righty; 

去RootViewController的.M文件合成爲,

@synthesize lefty; 
@synthesize righty; 

後,在RootViewController.m只是這一個

- (IBAction)myBtnPushed{ 
    NSLog(@"myBtnPushed"); 


    lefty = [[Left alloc] initWithNibName:@"Left" bundle:[NSBundle mainBundle]]; 
    righty = [[Right alloc] initWithNibName:@"Right" bundle:[NSBundle mainBundle]]; 

    lefty.delegate=righty; 
    [self.navigationController pushViewController:lefty animated:YES]; 

    [detailViewController.navigationController pushViewController:righty animated:YES]; 


} 

在delloac寫這個替換你的函數,

[lefty release]; 
lefty = nil; 
[righty release]; 
righty = nil; 

它的完成,運行應用程序。我測試過了,完成了。

+0

請關閉大寫鎖定。 – 2011-04-27 17:29:56