代码之家  ›  专栏  ›  技术社区  ›  zs2020

关于委托的Objective-C设计模式问题

  •  0
  • zs2020  · 技术社区  · 14 年前

    我有一个实现了许多委托方法的类。如何按照委托方法所属的协议将委托方法分组到不同的类中,并在原始类中使用它们?

    1 回复  |  直到 14 年前
        1
  •  2
  •   kennytm    14 年前

    与创建许多类不同,更简单的解决方案是将类划分为不同的类别:

    @interface MyViewController : UIViewController {
      ...
    }
    ...
    @end
    
    
    @interface MyViewController (TableStuff) <UITableViewDataSource, UITableViewDelegate>
    // methods related to table stuff
    @end
    
    
    @interface MyViewController (SearchStuff) <UISearchBarDelegate>
    // methods related to table stuff
    @end