Closed guoxj closed 12 years ago
i comment out - (void)willMoveToSuperview:(UIView *)newSuperview
and move [self startObservingScrollView]; to initWithScrollView,
and now it's working!
@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.
in loadView, i init the tableview and add the handler
(void)loadView { CGRect rect = APPFRAME; self._nearByPersonTableView = [[[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain] autorelease];
//..... [self._nearByPersonTableView addPullToRefreshWithActionHandler:^{ [self refresh]; }];
[self._nearByPersonTableView addInfiniteScrollingWithActionHandler:^{ [self loadMoreTaped]; }];
//.... }
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.
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:
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;
@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
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.
@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.
hi,i have just update SVPullToRefresh ,and i found that addInfiniteScrollingWithActionHandler is not working now