[英]Passing a delegate to another view controller's delegate
我正在用Objective-C编写的应用程序中构建一个功能。 我无法发布代码,但我会尽力描述自己的世界。 我面临的问题与代表有关。
AlphaViewController
将ConnectionView
作为其delegate
。 它有助于添加对提供给AlphaViewController
数据执行一些操作,我们在AlphaViewController's
视图上显示输出。
当您单击AlphaViewController
的按钮时,我将显示一个UIAlertController
。 从中可以单击一个按钮以打开ReportView
。 BetaViewController
创建ReportView
。
BetaViewController
具有ReportGenerator
作为其delegate
。 ReportGenerator
有助于生成一些HTML,这些HTML在BetaViewController's
视图中呈现。
我的问题是,我想用ConnectionView's
输出(我相信是的一部分ConnectionView
在对象AlphaViewController
),在ReportGenerator
处理它,然后呈现HTML数据BetaViewController's
看法。
我一直在四处寻找解决方案,但还没有找到任何答案。 我对代表不好。
请协助我在这里达成目标。 对不起,我无法发布代码。
ConnectionView's
输出从AlphaViewController
到BetaViewController
。 当分配BetaViewController
为代表ReportGenerator
通数据,即ConnectionView's
输出ReportGenerator
并获得ReportGenerator
处理它,然后呈现HTML数据BetaViewController's
看法。 它看起来似乎很复杂,但是可以实现。
还有第二种方法比使用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.