gpt4 book ai didi

iphone - splitViewController 具有两个 NavigationController 链接协议(protocol)

转载 作者:行者123 更新时间:2023-12-03 20:46:56 24 4
gpt4 key购买 nike

编辑:添加源项目

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

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

然后,当单击工具栏项时,我会弹出一个新的 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];

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

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

我能够按预期通过协议(protocol)完成回访。

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

最佳答案

好吧,我知道回答很晚了,但我认为这个答案是完美且有效的。尝试一下。打开 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;

已完成,运行您的应用程序。我测试了一下,已经完成了。

关于iphone - splitViewController 具有两个 NavigationController 链接协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5263128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com