Coder Social home page Coder Social logo

bhavingupta / bottom-referesh-control-uitableview Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 22 KB

Smooth scrolling bottom refresh control for table view with some objects in array.

Objective-C 100.00%
ios8 ios10 objective-c iphone ipad uitableview uiactivityindicatorview pagination-support uirefreshcontrol

bottom-referesh-control-uitableview's Introduction

Bottom-Referesh-Control-UITableView

Smooth scrolling bottom refresh control for table view with some objects in array.

Just add some dummy data into array with custom referesh control cell in table view or handle response from web service and populate the data into the array with smooth animation from table view top with this two methods

Make sure these given below methods are very important to show the cell at the end of the table view with your conditional array objects so that you can show the load more cell in table view with concerned API call for loading more data to an array.

Please go through the demo once and let me know if any query regarding this demo of bottom referesh control.

These were the methods to focus on while loading more data into cell with load more custom cell in table view as below:

Step 1 :

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.objects.count + 1;
    }

Step 2 :

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellStandardIdentifier = @"Cell";
        static NSString *cellLoadingIdentifier = @"Loading";

        if (indexPath.row < self.objects.count) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStandardIdentifier forIndexPath:indexPath];
            cell.textLabel.text = self.objects[indexPath.row];
            return cell;
        } else {
            LoadingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellLoadingIdentifier forIndexPath:indexPath];
            [cell.activityIndicatorView startAnimating];
            [self fetchMoreData];
            return cell;
        }
    }

Step 3 :

    - (void)fetchMoreData {
        static BOOL fetchInProgress = FALSE;

        if (fetchInProgress)
            return;

        typeof(self) __weak weakSelf = self;

        fetchInProgress = TRUE;

        // this simulates a background fetch; I'm just going to delay for a second
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            typeof(self) strongSelf = weakSelf;
            if (strongSelf) {
                NSArray *indexPaths = [strongSelf addSomeObjects];
                [strongSelf.tableView beginUpdates];
                [strongSelf.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
                fetchInProgress = FALSE;
                [strongSelf.tableView endUpdates];
            }
        });
    }

Step 4 :

    - (NSArray *)addSomeObjects {
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        formatter.numberStyle = NSNumberFormatterSpellOutStyle;
        NSMutableArray *indexPaths = [NSMutableArray array];
        for (NSInteger i = 0; i < 20; i++) {
            [self.objects addObject:[formatter stringFromNumber:@([self.objects count] + 1)]];
            [indexPaths addObject:[NSIndexPath indexPathForRow:self.objects.count - 1 inSection:0]];
        }
        return indexPaths;
    }

bottom-referesh-control-uitableview's People

Contributors

bhavingupta avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.