繁体   English   中英

将委托传递给另一个视图控制器的委托

[英]Passing a delegate to another view controller's delegate

我正在用Objective-C编写的应用程序中构建一个功能。 我无法发布代码,但我会尽力描述自己的世界。 我面临的问题与代表有关。

  1. AlphaViewControllerConnectionView作为其delegate 它有助于添加对提供给AlphaViewController数据执行一些操作,我们在AlphaViewController's视图上显示输出。

  2. 当您单击AlphaViewController的按钮时,我将显示一个UIAlertController 从中可以单击一个按钮以打开ReportView BetaViewController创建ReportView

  3. BetaViewController具有ReportGenerator作为其delegate ReportGenerator有助于生成一些HTML,这些HTML在BetaViewController's视图中呈现。

我的问题是,我想用ConnectionView's输出(我相信是的一部分ConnectionView在对象AlphaViewController ),ReportGenerator处理它,然后呈现HTML数据BetaViewController's看法。

我一直在四处寻找解决方案,但还没有找到任何答案。 我对代表不好。

请协助我在这里达成目标。 对不起,我无法发布代码。

  1. 您可以在推送之前将ConnectionView's输出从AlphaViewControllerBetaViewController 当分配BetaViewController为代表ReportGenerator通数据,即ConnectionView's输出ReportGenerator并获得ReportGenerator处理它,然后呈现HTML数据BetaViewController's看法。

它看起来似乎很复杂,但是可以实现。

  1. 还有第二种方法比使用AppDelegate方法简单得多。 您可以在AppDelegate类中声明和定义属性,并可以从类中的任何位置访问它。

     //Interface: @interface MyAppDelegate : NSObject { NSString *yourString; // Declare your object } @property (nonatomic, strong) NSString *yourString; ... @end //and in the .m file for the App Delegate @implementation MyAppDelegate @synthesize yourString; yourString = some string; @end //You can access the property to save and retrieve your file. You can save MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate]; appDelegate.yourString = some NSString; //..to write 

您可以按照您的要求在BetaViewController或ReportGenerator中读取值

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
someString = appDelegate.myString;  //..to read

对于没有。 可以创建模型类的属性,并按上面的定义访问它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM