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

addInfiniteScrollingWithActionHandler not working now #37

Closed guoxj closed 12 years ago

guoxj commented 12 years ago

hi,i have just update SVPullToRefresh ,and i found that addInfiniteScrollingWithActionHandler is not working now

guoxj commented 12 years ago

i comment out - (void)willMoveToSuperview:(UIView *)newSuperview
and move [self startObservingScrollView]; to initWithScrollView, and now it's working!

chapados commented 12 years ago

@guoxj I committed the change that seems to have broken your code and I'm trying to understand why it's failing for you. Where are you calling the -addInfiniteScrollingWithActionHandler method? Also, do you really need to comment out -willMoveToSuperview: or does simply adding a call to [self startObservingScrollView] to initWithScrollView fix the problem? Would you be willing to dump your actionHandler block and the surrounding code into a gist. It might help figure out what's wrong.

guoxj commented 12 years ago

in loadView, i init the tableview and add the handler

and i have tried to add a call to [self startObservingScrollView] to initWithScrollView,but it does't work for me. the willMoveToSuperview got called multiple time,and finally the observer got removed.

chapados commented 12 years ago

Hmm.. if you add the handlers in -loadView, then the parent view hierarchy (self.view) has not been created yet, though I'm not sure why this would prevent the handler from working. Is the issue that -[SVPullToRefresh willMoveToSuperview:] is not being called? Also, is this broken in general, or is it on a specific version of iOS? It would be helpful if you could test 2 changes independently, one to your code, and one to SVPullToRefresh:

Switch back to the current master of SVPullToRefresh and change your code to add the action handlers in -viewDidLoad instead of -loadView. This will ensure that the complete responder chain (including your view controller) is setup.

Change your current patch to SVPullToRefresh so that instead of commenting out -willMoveToSuperview, you just add a call to [self startObservingScrollView] to initWithScrollView:

guoxj commented 12 years ago

i have reproduced the bug in the demo code.[SVPullToRefreshDemo]

Just set the table footView in SVViewController.m in line 31:

UIButton *loadMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom]; tableView.tableFooterView = loadMoreBtn;

chapados commented 12 years ago

@guoxj The reason that setting tableView.tableFooterView on line 31 causes the infiniteScrollView to disappear is because SVPullToRefresh adds itself to the tableView.tableFooterView in order to display the loading status. If you look at SVPullToRefresh.m:L194 you'll see where this is set. Right now, setting the tableFooterView after setting the infiniteScrollingActionHandler is not supported. Is this what you are doing in your original code? If so, I'm having a hard time understanding how your proposed change would solve this problem. Also, the infinite scrolling feature tracks the content offset and automatically triggers when reaching the last cell, so it's not clear to me why you would want to have 'Load More' button in the tableFooterView... That said, if you need to display a custom tableFooter, one approach would be to set tableView.tableFooterView before calling addInfiniteScrollingActionHandler:. Then in cases where you don't want to infinite scrolling, call tableView.showsInfiniteScrolling = NO, which will disable infiniteScrolling and restore your custom tableFooterView

guoxj commented 12 years ago

yes,that's the way i do in my original code.

i comment out the "- (void)willMoveToSuperview:(UIView )newSuperview" and move [self startObservingScrollView]; into - (id)initWithScrollView:(UIScrollView )scrollView

and it works. in the demo code, it also works

later,i will try to change my code to fix that.

samvermette commented 12 years ago

@chapados is right that you shouldn't be showing a "load more" button if you're using the infinite scrolling feature of SVPullToRefresh. The activity indicator is nothing but a temporary transition to the additional data that is about to get appended to the table view. If no more data is available, only then you could be changing the table view's footer view (to a small dot for instance) if setting showsInfiniteScrolling to NO isn't enough.