-
-
Save logicaroma/909704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | |
{ | |
if(_reachedEndOfFeed) return; | |
if(!_dynamicFeed) return; | |
DLog(); | |
if (!reloading) | |
{ | |
checkForRefresh = YES; // only check offset when dragging | |
} | |
} | |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView | |
{ | |
if (reloading) return; | |
if(scrollView.contentSize.height - scrollView.contentOffset.y < (self.view.bounds.size.height)) { | |
if(delegate_ != nil && [delegate_ respondsToSelector:@selector(infiniteTableViewController:requestsNextTitlesForPage:)]) { | |
reloading=YES; | |
DLog(@"Will request more at page %d", (currentPage_ + 1)); | |
[delegate_ infiniteTableViewController:self requestsNextTitlesForPage:(currentPage_ + 1)]; | |
[self startLoadingAnimation]; | |
} | |
} | |
} | |
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView | |
willDecelerate:(BOOL)decelerate | |
{ | |
if (reloading) return; | |
if(_reachedEndOfFeed) return; | |
if(!_dynamicFeed) return; | |
DLog(@"Scrollview offset y %f", scrollView.contentOffset.y); | |
DLog(@"Scrollview height %f", scrollView.contentSize.height); | |
DLog(@"Bounds height %f", self.view.bounds.size.height); | |
if(scrollView.contentSize.height - scrollView.contentOffset.y < (self.view.bounds.size.height * 2)) { | |
if(delegate_ != nil && [delegate_ respondsToSelector:@selector(infiniteTableViewController:requestsNextTitlesForPage:)]) { | |
reloading=YES; | |
DLog(@"Will request more at page %d", (currentPage_ + 1)); | |
[delegate_ infiniteTableViewController:self requestsNextTitlesForPage:(currentPage_ + 1)]; | |
[self startLoadingAnimation]; | |
} | |
} | |
checkForRefresh = NO; | |
} | |
- (void) startLoadingAnimation { | |
if(loadingCell!=nil && activityView!=nil) { | |
[loadingCell.textLabel setText:@"Loading..."]; | |
[activityView startAnimating]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopLoadingAnimations) name:kConnectivityErrorNotification object:nil]; | |
id appDelegate = [[UIApplication sharedApplication] delegate]; | |
if (appDelegate != nil && [appDelegate respondsToSelector:@selector(checkReachability)]) { | |
[appDelegate checkReachability]; | |
} | |
} | |
} | |
- (void) stopLoadingAnimations { | |
if(loadingCell!=nil && activityView!=nil) { | |
[activityView stopAnimating]; | |
[loadingCell.textLabel setText:@"Load more..."]; | |
reloading = NO; | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:kConnectivityErrorNotification object:nil]; | |
} | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForLoadMoreAtIndexPath:(NSIndexPath *)indexPath { | |
static NSString *LoadingCellIdentifier = @"LoadingCell"; | |
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LoadingCellIdentifier]; | |
if (loadingCell == nil) { | |
loadingCell = [[[ClearLabelsCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LoadingCellIdentifier] autorelease]; | |
loadingCell.backgroundView = [[[GradientView alloc] init] autorelease]; | |
[loadingCell setSelectionStyle:UITableViewCellSelectionStyleBlue]; | |
[loadingCell.textLabel setTextColor:[UIColor colorWithRed:55.0/255.0 green:90.0/255.0 blue:163.0/255.0 alpha:1.0]]; | |
[loadingCell.textLabel setTextAlignment:UITextAlignmentCenter]; | |
loadingCell.backgroundColor = [UIColor clearColor]; | |
if([titles count] == 0) { | |
reloading = YES; | |
[loadingCell.textLabel setText:@"Loading..."]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopLoadingAnimations) name:kConnectivityErrorNotification object:nil]; | |
id appDelegate = [[UIApplication sharedApplication] delegate]; | |
if (appDelegate != nil && [appDelegate respondsToSelector:@selector(checkReachability)]) { | |
[appDelegate checkReachability]; | |
} | |
} | |
else { | |
[loadingCell.textLabel setText:@"Load more..."]; | |
reloading = NO; | |
} | |
loadingCell.textLabel.shadowColor = [UIColor whiteColor]; | |
loadingCell.textLabel.shadowOffset = CGSizeMake(1, 1); | |
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; | |
activityView.frame = CGRectMake(25.0f, 88.0f - 38.0f, 20.0f, 20.0f); | |
activityView.hidesWhenStopped = YES; | |
if([titles count] == 0) | |
[activityView startAnimating]; | |
[loadingCell setAccessoryView:activityView]; | |
[activityView release]; | |
} | |
return loadingCell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment