简体   繁体   English

UITableView方法 - 委托,观察者或通知中心

[英]UITableView method - delegate, observer or notificagtion center

I have a UITableView on a ViewController which implement the delegate methods to handle the UITableView stuff - adding to the table etc. All fine, but now I need another Object to handle scrollViewDidScroll from the table. 我在ViewController上有一个UITableView,它实现委托方法来处理UITableView的东西 - 添加到表等等。一切都很好,但是现在我需要另一个Object来处理来自表的scrollViewDidScroll

@imp ObjecteOne <UITableviewDelegate>
        - ViewDidLoad{
        [ObjectTwo setScrollView:_tableview];
        }
@end


@imp ObjectTwo
    - (void) setScrollView:(NSScrollView)view{
     // Would you do:
     [view addObserver??? @selector("scrollViewDidScroll") // something
     or          
    }

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    // do stuff
    }

@end

About all you can do is arrange for your ViewController to forward the scroll view delegate methods to the secondary object. 您可以做的就是安排ViewController将滚动视图委托方法转发给辅助对象。 One of the drawbacks of the delegate model is that there can only be one delegate at a time. 委托模型的缺点之一是一次只能有一个委托。 (A better implementation by Apple might've been to have a tableDelegate separate the scrollView delegate) (Apple更好的实现可能是让tableDelegate将scrollView委托分开)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM