samvermette / SVPullToRefresh

Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.
http://samvermette.com/314
MIT License
4.82k stars 1.09k forks source link

Changing the pullToRefresh action handler? #238

Open JinkProject opened 9 years ago

JinkProject commented 9 years ago

Is there a way to override, change or reset the action handler the pullToRefresh view is performing? I have a view controller that's being loaded initially to show the user's feed. I have a modal view, the search view, that reloads the collection view with the search term the user enters. Since the pullToRefresh has an action handler already attached to it, I can't override it, reset or change it to fit the updated request.

janakiramreddy commented 9 years ago

Hey. were you able to find a solution to this?

sree127 commented 9 years ago

Hey, I was able to achieve this using a small tweak :

Inside SVInfiniteScrollingView,

- (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler {

    if(!self.infiniteScrollingView) {
        SVInfiniteScrollingView *view = [[SVInfiniteScrollingView alloc] initWithFrame:CGRectMake(0, self.contentSize.height, self.bounds.size.width, SVInfiniteScrollingViewHeight)];
        view.infiniteScrollingHandler = actionHandler;
        view.scrollView = self;
        [self addSubview:view];

        view.originalBottomInset = self.contentInset.bottom;
        self.infiniteScrollingView = view;
        self.showsInfiniteScrolling = YES;
    }
    else
    {
        SVInfiniteScrollingView *view = self.infiniteScrollingView;
        view.infiniteScrollingHandler = actionHandler;
        view.scrollView = self;
        [self addSubview:view];

        view.originalBottomInset = self.contentInset.bottom;
        self.infiniteScrollingView = view;
        self.showsInfiniteScrolling = YES;
    }
}