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