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

时间:2017-07-26 04:10:25

标签: ios objective-c uiviewcontroller delegates

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

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

  2. 当您点击AlphaViewController中的按钮时,我会显示UIAlertController。我可以点击按钮打开ReportViewBetaViewController创建ReportView

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

  4. 我的问题是,我想在{{1}中使用ConnectionView's输出(我相信它是ConnectionView中的AlphaViewController对象的一部分)处理它,然后在ReportGenerator视图中以HTML格式呈现数据。

    我一直在努力寻找解决方案,但我们无法找到任何解决方案。我对代表不好。

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

1 个答案:

答案 0 :(得分:0)

  1. 您可以在推送之前将ConnectionView's的输出从AlphaViewController传递到BetaViewController。当您将BetaViewController作为ReportGenerator传递数据的委托,即ConnectionView's输出分配给ReportGenerator并让ReportGenerator处理它,然后以HTML格式呈现数据时BetaViewController's查看。
  2. 语言似乎很复杂,但可以实现。

    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
      
    2. Yo可以根据您的要求读取BetaViewController或ReportGenerator中的值

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

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

相关问题