Mashhadi
Mashhadi

Reputation: 3024

How to reload UITableView step by step?

I am working on an application and i have to show 10 records in table view one time then if user want to see more records then user will have to click on "see more records" cell, then user will be able to see more records.

If any one know about this then please give me solution. Thanx

Upvotes: 0

Views: 204

Answers (1)

kviksilver
kviksilver

Reputation: 3854

This is simple prototype of what you can do:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if ([self.tableData count]>window) {
        return window+1;
    }
    else{
        return [self.tableData count];
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    if (indexPath.row<window) {
        cell.textLabel.text=[self.tableData objectAtIndex:indexPath.row];

    }
   else{
        cell.textLabel.text=@"LoadMore";

    }
    return cell;



}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==window) {
        window=window+step;
        [tableView reloadData];

    }

}

table data is an array that contains data that you want to show in tableview, window is number of lines to show initially and is used to set range of what to show, step is number of new items to add in every new load

Upvotes: 1

Related Questions