开发者

Must I call super when I implement -scrollViewDidScroll: of UIScrollViewDelegate in an UITableView?

开发者 https://www.devze.com 2022-12-27 06:43 出处:网络
I made a custom UITableView subclass and implemented this: - (void)scrollViewDidScroll:(UIScrollView *)scrollView {

I made a custom UITableView subclass and implemented this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // scrolled...
}

Now, what I think is that UITableView may also love to get this message for some obvious reasons. However, when I don't forward that to super, for some reason, everything still works fine. Must I forward that guy to super? I mean...it's a delegate method implementation, but as far as I'm aware of, this would still override anythi开发者_开发知识库ng implemented in UITableView, or not?

Edit: I see...the delegate could be anyone. Never mind about this. BUT: What I have such a thing in a superclass, and make a subclass. How would I even know that the superclass does implement that method and I must forward it to super?


Short answer: no.
Those methods are defined in the UIScrollViewDelegate Protocol.
They are meant to be implemented in a delegate, which maybe only has NSObject as parent.

It does not override anything, as it's a delegate method.
The UIScrollView just does it's stuff, and calls the delegate method if a delegate is set.


This is a delegate method which means it gets called by your instance of UITableView for your convenience.

The scrolling happens and the UITableView internal code will call.

if ([delegate respondsTo:@selector(scrollViewDidScroll:)]) {
    [delegate performSelector:@selector(scrollViewDidScroll:) withObject:[self scrollView]];
}

And so you use this method to implement additional functionality, for example activating a control when the tableView has scrolled a certain amount.

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消