Method not working on second time through: SVPullToRefresh

♀尐吖头ヾ 提交于 2019-12-23 04:42:09

问题


So, I've made some progress on my issue described here — https://stackoverflow.com/questions/27348458/svpulltorefresh-infinite-scroll-with-an-rss-feed

Nonetheless, I have a problem. The table loads 10 YouTube videos initially. Then, the second ten will load using

__weak MasterViewController *weakSelf = self;

[self.tableView addInfiniteScrollingWithActionHandler:^{

    NSLog(@"Infinite Scroll");
    [weakSelf updateVideoList];

}];

-(void) updateVideoList essentially adds 10 items to the array that loads into the table view (reloadData is called on the tableview at the end after addObjectsFromArray adds items to the initial array). This works well enough. The problem is that trying to load a third 10 items does not work. I added the NSLog to see if it even goes into the method a second time, and it doesn't.

Is there any reason for the method to not work a second time?

Edit Here's updateVideoList, but I used the log to determine that the method isn't even called the second time through:

- (void) updateVideoList {

NSString *baseDomain = @"https://gdata.youtube.com/feeds/api/videos";
NSString *maxresults = @"10";
NSString *startIndex = [NSString stringWithFormat:@"%lu", (unsigned long)videoList.count+1];
NSString *orderBy = @"published";
NSString *author = @"theverge";
NSString *extension = @"v=2&alt=jsonc";
NSString *urlYoutube = [NSString stringWithFormat:@"%@?max-results=%@&start-index=%@&orderby=%@&author=%@&%@",
                        baseDomain,maxresults, startIndex,orderBy,author,extension];

NSDictionary *listOfVideos = [JSONParser listOfVideos:urlYoutube];
int videoListSize = [[[listOfVideos valueForKey:@"data"] valueForKey:@"totalItems"]  intValue];
if (videoListSize>0) {
    NSMutableArray *secondYoutubeList = [[NSMutableArray alloc] init];
    NSArray *arrayVideoList = [[listOfVideos valueForKey:@"data"] valueForKey:@"items"];
    for (NSDictionary *videoDictionary in arrayVideoList) {
        NSString *idVideo = [videoDictionary valueForKey:@"id"];
        NSString *description = [videoDictionary valueForKey:@"description"];
        //NSString *updated = [videoDictionary valueForKey:@"updated"];

        //            NSString *departTimeDate = [videoDictionary valueForKey:@"updated"];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
        //NSDate *date = [dateFormatter dateFromString:departTimeDate];

        NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
        NSInteger day = [components day];
        NSInteger month = [components month];
        NSInteger year = [components year];

        NSString *updated = [NSString stringWithFormat:@"%ld, %ld, %ld", (long)month,(long)day,(long)year];

        NSString *duration = [videoDictionary valueForKey:@"duration"];

        NSString *title = [videoDictionary valueForKey:@"title"];

        // If we are using wifi, take hqDefault
        NSString *thumbnail = [[videoDictionary valueForKey:@"thumbnail"] valueForKey:@"hqDefault"];
        YoutubeVideo *video = [[YoutubeVideo alloc] initWithId:idVideo withDescription:description withUpdated:updated withDuration:duration withTitle:title withThumbnail:thumbnail];
        [secondYoutubeList addObject:video];

    }
    [videoList addObjectsFromArray:secondYoutubeList];
    [self.tableView reloadData];
}
}

回答1:


You should call

[self.tableView.infiniteScrollingView stopAnimating];

Once your work of reloading is got completed.



来源:https://stackoverflow.com/questions/27358739/method-not-working-on-second-time-through-svpulltorefresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!