<bdo id='t6D1L'></bdo><ul id='t6D1L'></ul>
<tfoot id='t6D1L'></tfoot>

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

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

    1. <legend id='t6D1L'><style id='t6D1L'><dir id='t6D1L'><q id='t6D1L'></q></dir></style></legend>

        打开和关闭其他 UIViewControllers - 除了使用协议 &amp; 之外的任何其他方法代表?

        opening and closing other UIViewControllers - any other approaches than to use protocol amp; delegate?(打开和关闭其他 UIViewControllers - 除了使用协议 amp; 之外的任何其他方法代表?)

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

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

            • <bdo id='KMQKm'></bdo><ul id='KMQKm'></ul>

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

              <legend id='KMQKm'><style id='KMQKm'><dir id='KMQKm'><q id='KMQKm'></q></dir></style></legend>
                  <tbody id='KMQKm'></tbody>
                  本文介绍了打开和关闭其他 UIViewControllers - 除了使用协议 &amp; 之外的任何其他方法代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  从 FirstVC 屏幕中打开另一个屏幕的正常方法是这样的:

                  The normal way to open another screen from within a FirstVC screen, so one can close it again is like this:

                      SecondVC *secondVC = [[SecondVC alloc] initWithNibName:@"SecondVC" bundle:nil];
                      secondVC.delegate = self; //needed to dismiss
                      [self presentModalViewController: secondVC animated: YES];
                  

                  SecondVC.m 必须导入一个协议,该协议声明调用关闭 SecondVC 的方法

                  while the SecondVC.m has to import a protocol that declares the method called to close the SecondVC

                  所以我总是要创建一个协议文件 SecondVCProtocol.h,它基本上看起来像这样:

                  So I always have to create a protocol file SecondVCProtocol.h which basically looks like this:

                  @protocol SecondVCProtocol <NSObject>
                  -(void)secondVCDidFinish;
                  @end
                  

                  然后在 SecondVC.m 我需要导入这个 SecondVCProtocol.h 文件,现在终于可以调用了

                  Then in SecondVC.m I need to import this SecondVCProtocol.h file and now can finally call

                   [self.delegate    secondVCDidFinish]
                  

                  我刚刚完成了另一个 Android 应用程序,回到 iOS 世界,我觉得这很麻烦.- 需要在单独的文件中定义这样的协议 &需要使用委托 - 只是为了完成最正常的任务,比如关闭屏幕......

                  I have just completed another Android app and beeing back in the iOS world, I find this rather cumbersome. - needing to define such a protocol in a separate file & needing to use a delegate - all just to do the most normal task like closing a screen...

                  难道没有更简单、不那么复杂的方法吗?还是必须这样做?

                  例如像 SecondVC 中的 [self dismiss] - 没有委托,没有协议 - 他不是很好吗?

                  for example like [self dismiss] in SecondVC - no delegate, no protocol - wouldn't his be really nice?

                  非常感谢!

                  推荐答案

                  你可以直接调用

                  dismissViewControllerAnimated:completion:
                  

                  在呈现的视图控制器上,虽然这并不是最佳实践.

                  on the presented viewcontroller, although it is not exactly best practice.

                  来自 Apple 的文档:

                  From Apple's documentation:

                  呈现视图控制器负责关闭视图它呈现的控制器.如果您在呈现的视图上调用此方法控制器本身,它会自动将消息转发到呈现视图控制器.

                  The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

                  也来自 Apple 的文档(http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html)

                  Also from Apple's documentation though (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html)

                  当需要关闭呈现的视图控制器时,首选方法是让呈现视图控制器关闭它.换句话说,只要有可能,同一个视图控制器提出的视图控制器也应该负责解雇它.虽然有几种技术可以通知呈现视图控制器,其呈现的视图控制器应该被解雇,首选技术是委托.

                  When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it. Although there are several techniques for notifying the presenting view controller that its presented view controller should be dismissed, the preferred technique is delegation.

                  这篇关于打开和关闭其他 UIViewControllers - 除了使用协议 &amp; 之外的任何其他方法代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

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

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

                        <bdo id='OxQyK'></bdo><ul id='OxQyK'></ul>
                        <tfoot id='OxQyK'></tfoot>