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

我正在使用Objective-C编写的应用程序中构build一个function。 我不能张贴代码,但我会尽力描述我的世界。 我面临的问题与代表有关。

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

  2. 当你点击AlphaViewController一个button时,显示一个UIAlertController 。 从中我可以点击一个button来打开ReportViewBetaViewController创buildReportView

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

我的问题是,我想使用ConnectionView's输出(我相信是AlphaViewControllerConnectionView对象的AlphaViewController ,在ReportGenerator中处理它,然后在BetaViewController's视图中呈现HTML中BetaViewController's数据。

我一直在搞乱find一个解决scheme,但一直没能弄清楚什么。 代表我不好。

请帮助我在这里实现我的目标。 对不起,我不能发布代码。

  1. 在推送之前,您可以将ConnectionView's输出从AlphaViewControllerBetaViewController 。 当您将您的BetaViewController分配给ReportGenerator传递数据的委托时, ReportGenerator ConnectionView's输出分配给ReportGenerator并让ReportGenerator处理它,然后在BetaViewController's视图中以HTML格式呈现数据。

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

  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 

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