splitViewController与两个NavigationController链接协议

时间:2011-03-10 17:04:12

标签: iphone uinavigationcontroller uisplitviewcontroller ipad

编辑:添加了源项目

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

我创建了一个基于Split View的应用程序。然后我在MainWindow.xib中的DetailViewController中添加了第二个UINavigationController。

然后在单击工具栏项时弹出一个新的UIViewController子类。我使用以下代码来执行pop:

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];

这很有效。我遇到的问题是如何将信息或函数调用从拆分视图的主侧传递到拆分视图的详细信息侧?

如果我通过以下方法呈现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 <--

1 个答案:

答案 0 :(得分: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;

已经完成,运行你的应用程序。我测试过,已经完成了。