• <tfoot id='HqIis'></tfoot>

      <small id='HqIis'></small><noframes id='HqIis'>

        <legend id='HqIis'><style id='HqIis'><dir id='HqIis'><q id='HqIis'></q></dir></style></legend>

          <bdo id='HqIis'></bdo><ul id='HqIis'></ul>

      1. <i id='HqIis'><tr id='HqIis'><dt id='HqIis'><q id='HqIis'><span id='HqIis'><b id='HqIis'><form id='HqIis'><ins id='HqIis'></ins><ul id='HqIis'></ul><sub id='HqIis'></sub></form><legend id='HqIis'></legend><bdo id='HqIis'><pre id='HqIis'><center id='HqIis'></center></pre></bdo></b><th id='HqIis'></th></span></q></dt></tr></i><div id='HqIis'><tfoot id='HqIis'></tfoot><dl id='HqIis'><fieldset id='HqIis'></fieldset></dl></div>

        “代表"的替代方案是什么?在控制器之间传递数据?

        时间:2023-09-12
            <tbody id='Vx6tE'></tbody>

              <legend id='Vx6tE'><style id='Vx6tE'><dir id='Vx6tE'><q id='Vx6tE'></q></dir></style></legend>
              1. <small id='Vx6tE'></small><noframes id='Vx6tE'>

                  <bdo id='Vx6tE'></bdo><ul id='Vx6tE'></ul>
                  <i id='Vx6tE'><tr id='Vx6tE'><dt id='Vx6tE'><q id='Vx6tE'><span id='Vx6tE'><b id='Vx6tE'><form id='Vx6tE'><ins id='Vx6tE'></ins><ul id='Vx6tE'></ul><sub id='Vx6tE'></sub></form><legend id='Vx6tE'></legend><bdo id='Vx6tE'><pre id='Vx6tE'><center id='Vx6tE'></center></pre></bdo></b><th id='Vx6tE'></th></span></q></dt></tr></i><div id='Vx6tE'><tfoot id='Vx6tE'></tfoot><dl id='Vx6tE'><fieldset id='Vx6tE'></fieldset></dl></div>
                  <tfoot id='Vx6tE'></tfoot>
                • 本文介绍了“代表"的替代方案是什么?在控制器之间传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否有替代委托"的方法将数据从一个控制器传回另一个控制器?

                  Are there alternatives to "delegates" to pass back data from one controller to another?

                  实现一个委托似乎需要做很多工作,只是为了将结果从子控制器传回给父控制器.没有别的方法吗?块"是一个答案吗?如果是这样,一些示例代码会很棒.

                  Just seems like a lot of work implementing a delegate just to pass back the result from a child controller, back to the parent controller. Is there not another method? Are "blocks" one answer, and if so some example code would be great.

                  推荐答案

                  你可以使用很多方法:

                  1. 调用超级控制器的方法,可能需要强制转换
                  2. 通知
                  3. 简单的Key-Value-Observing
                  4. 核心数据

                  1 的示例.

                  你的 MainViewController 的接口:为要传递的数据添加一个公共方法

                  - (void)newDataArrivedWithString:(NSString *)aString;
                  

                  MainViewController 显示 ChildController

                  - (void)showChildController
                  {
                      ChildController *childController = [[ChildController alloc] init];
                      childController.mainViewController = self;
                  
                      [self presentModalViewController:childController animated:YES];
                  
                      [childController release];
                  }
                  

                  子控制器头/接口:为mainViewController添加一个属性

                  @class MainViewController;
                  
                  @interface ChildController : UIViewController {
                      MainViewController *mainViewController;   
                  }
                  
                  @property (nonatomic, retain) MainViewController *mainViewController;
                  

                  子控制器向 MainViewController 传递数据

                  - (void)passDataToMainViewController
                  {
                      NSString * someDataToPass = @"foo!";
                      [self.mainViewController newDataArrivedWithString:someDataToPass];
                  }
                  

                  这篇关于“代表"的替代方案是什么?在控制器之间传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:获取对 UIApplication 委托的引用 下一篇:iOS Multipeer 连接框架invitationHandler 似乎不接受?

                  相关文章

                  <legend id='Y1Gn1'><style id='Y1Gn1'><dir id='Y1Gn1'><q id='Y1Gn1'></q></dir></style></legend>
                  <tfoot id='Y1Gn1'></tfoot>

                  <small id='Y1Gn1'></small><noframes id='Y1Gn1'>

                    • <bdo id='Y1Gn1'></bdo><ul id='Y1Gn1'></ul>
                    <i id='Y1Gn1'><tr id='Y1Gn1'><dt id='Y1Gn1'><q id='Y1Gn1'><span id='Y1Gn1'><b id='Y1Gn1'><form id='Y1Gn1'><ins id='Y1Gn1'></ins><ul id='Y1Gn1'></ul><sub id='Y1Gn1'></sub></form><legend id='Y1Gn1'></legend><bdo id='Y1Gn1'><pre id='Y1Gn1'><center id='Y1Gn1'></center></pre></bdo></b><th id='Y1Gn1'></th></span></q></dt></tr></i><div id='Y1Gn1'><tfoot id='Y1Gn1'></tfoot><dl id='Y1Gn1'><fieldset id='Y1Gn1'></fieldset></dl></div>