<legend id='YFfit'><style id='YFfit'><dir id='YFfit'><q id='YFfit'></q></dir></style></legend>
        <bdo id='YFfit'></bdo><ul id='YFfit'></ul>

      1. <small id='YFfit'></small><noframes id='YFfit'>

        <i id='YFfit'><tr id='YFfit'><dt id='YFfit'><q id='YFfit'><span id='YFfit'><b id='YFfit'><form id='YFfit'><ins id='YFfit'></ins><ul id='YFfit'></ul><sub id='YFfit'></sub></form><legend id='YFfit'></legend><bdo id='YFfit'><pre id='YFfit'><center id='YFfit'></center></pre></bdo></b><th id='YFfit'></th></span></q></dt></tr></i><div id='YFfit'><tfoot id='YFfit'></tfoot><dl id='YFfit'><fieldset id='YFfit'></fieldset></dl></div>
        <tfoot id='YFfit'></tfoot>
      2. 每个对象有多个代表?

        时间:2023-09-12

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

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

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

                  本文介绍了每个对象有多个代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 UIScrollView 我需要子类化,并且在子类中我需要附加 UIScrollViewDelegate 以便我可以实现 viewForZoomingInScrollView 方法.

                  I have a UIScrollView that I need to subclass and within the subclass I need to attach the UIScrollViewDelegate so I can implement the viewForZoomingInScrollView method.

                  然后我有一个 UIViewController 我需要在其中实例化我创建的这个 UIScrollView 子类的对象,并且我还想让 UIViewController 成为 UIScrollViewDelegate 用于这个对象,所以我可以在这个 UIViewController 类中实现 scrollViewDidZoom.

                  Then I have a UIViewController where I need to instantiate an object of this UIScrollView subclass that I created, and I would also like to make the UIViewController a UIScrollViewDelegate for this object so I can implement scrollViewDidZoom in this UIViewController class.

                  如何让一个对象有两个委托?(我知道我可以很容易地只拥有一个委托并在那里实现这两种方法,但出于设计目的,我想按照我提到的方式来做).

                  How is it possible to make one object have two delegates? (I know I could easily just have one delegate and just implement both methods there, but for design purposes I'd like to do it the way that I'm mentioning).

                  推荐答案

                  你不想要一个有 2 个委托的对象.您希望让您的 customScrollView 保持其自己的 UIScrollViewDelegate 函数的责任.

                  You don't want an object with 2 delegates. You want to keep your customScrollView keep the responsibility of its own UIScrollViewDelegate functions.

                  要让您的 parentVC 也响应 UIScrollView 的委托方法,您必须在您的 customScrollView 中创建一个自定义委托.

                  To make your parentVC respond to the delegate methods of UIScrollView as well you will have to make a custom delegate inside your customScrollView.

                  在调用 UIScrollViewDelegate 函数的那一刻,您还将从自定义委托中调用您的委托函数之一.这样,您的 parentVC 将在您希望的时候做出响应.

                  At the moment a UIScrollViewDelegate function gets called you will also call one of your delegate functions from your custom delegate. This way your parentVC will respond at the moment you want it to.

                  看起来有点像这样.

                  CustomScrollView.h

                  CustomScrollView.h

                  @protocol CustomDelegate <NSObject>
                  
                  //custom delegate methods
                  -(void)myCustomDelegateMethod;
                  
                  @end
                  
                  @interface CustomScrollView : UIScrollView <UIScrollViewDelegate>
                  {
                      id<CustomDelegate> delegate
                      //the rest of the stuff
                  

                  CustomScrollView.m

                  CustomScrollView.m

                  -(void) viewForZoomingInScrollView
                  {
                      [self.delegate myCustomDelegateMethod];
                      //rest of viewForZoomingInScrollView code
                  

                  ParentVC.h

                  @interface CustomScrollView : UIViewController <CustomDelegate>
                  {
                      //stuff
                  

                  ParentVC.m

                  -(void)makeCustomScrollView
                  {
                       CustomScrollView *csv = [[CustomScrollView alloc] init];
                       csv.delegate = self;
                       //other stuff
                  
                  }
                  
                  -(void)myCustomDelegateMethod
                  {
                     //respond to viewForZoomingInScrollView
                  }
                  

                  我希望这可以完全解决您的问题.祝你好运.

                  I hope this fully covers your problem. Good luck.

                  这篇关于每个对象有多个代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:animationDidStop 方法的多个 CAAnimations? 下一篇:获取对 UIApplication 委托的引用

                  相关文章

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

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

                    <bdo id='SUiDY'></bdo><ul id='SUiDY'></ul>
                      <legend id='SUiDY'><style id='SUiDY'><dir id='SUiDY'><q id='SUiDY'></q></dir></style></legend><tfoot id='SUiDY'></tfoot>