Ios 在目标C的子类中重写delegateClass的方法

Ios 在目标C的子类中重写delegateClass的方法,ios,objective-c,uiscrollview,delegates,tableview,Ios,Objective C,Uiscrollview,Delegates,Tableview,我有一个类HomeViewController,它扩展了SectionController。我正在使用sectionController作为HomeViewController中的属性: @property (nonatomic, strong) SectionsController *sectionController 并将HomeViewController的viewDidLoad中的委托和datasource设置为: self.tableView.delegate = self.sect

我有一个类
HomeViewController
,它扩展了
SectionController
。我正在使用
sectionController
作为
HomeViewController
中的属性:

@property (nonatomic, strong) SectionsController *sectionController
并将
HomeViewController
viewDidLoad
中的委托和
datasource
设置为:

self.tableView.delegate = self.sectionController;
self.tableView.dataSource = self.sectionController;
SectionController
定义了一些
UIScrollViewDelegate
方法:

(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{    
}

(void)scrollViewDidScroll:(UIScrollView *)scrollView{
 }

(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
}
SectionController
是我的基类,并被更多的类扩展。我不希望在
SectionController
类中编写我的逻辑,相反,如果我可以在
HomeViewController
本身中重写这些
UIScrollViewDelegate
方法,会更方便


是否有方法重写这些方法?

是的,您可以在HomeViewController类中重写这些方法。只需在.m文件中定义相同的方法,如果您也想使用超类的代码,请按以下方式执行:

    (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
[super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
//Do your class specific things
    }

如果HomeViewController是SectionController的子类,为什么它会引用SectionController的其他实例?您应该将委托设置为
self
,然后您可以实现子类中所需的任何方法i agree with@Paulw11。这似乎是一个架构问题。您好@Paulw11我同意您的看法,但HomeViewController不是SectionController的子类,而是使用SectionController作为属性。。。很抱歉,我在发布问题时可能会造成误解。我尝试过用这种方式重写,但仍然会滚动调用基类的方法,而不是重写的方法。