开发者

iPhone load more tableViewCell

So I Have a design question for you. Basically I have an app in which I fetch 20 items from a server when the app loads, and displays them in a table view. I also have a loading table cell that appears in the last cell. What I want to do is when that cell appears, load the next 20 items and add them to the list and reload the table.

What recommendations do you guys have for doing something like this? Should I automaticall开发者_JS百科y fire off the request when the cell appears? Or should I wait for something else to do this? Any input would be appreciated. Thanks!


Personally, I'd fire off the request as soon as the cell appears. In fact, I'd consider firing the request before the cell appears - around cell 15 or so? That way the user is waiting for less time with a loading cell displayed.

However, that all depends on how big your data set is - if it's lots of data to get the next 20 rows I'd put something like 'press here for more results' and wait for the user's input to fire off the request.

The best way to find out which gives the best user experience is to do a quick user test - ask people who might be your customers to test the app and see which they seem happiest with. And take a look at apps like yours - what do they do - if they have set a precedent with your customers, perhaps you should try to follow that?


You can use following test code;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    totalElements = pageNumber*kNumberofElementsPerPage;
    int noOfrows = totalElements>[customerArray count]?[customerArray count]:totalElements+1;
    return noOfrows;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == totalElements&&totalElements!=0){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"loadMoreCell"];
        if(cell == nil){
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"loadMoreCell"];
        }
        cell.textLabel.text = @"Load More records";
        cell.detailTextLabel.text = [NSString stringWithFormat:@"Showing %d of %d records",totalElements,[customerArray count]];
        return cell;
    }
    ......
    ......
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == totalElements){
        pageNumber++;
        [customerTableView reloadData];
        return;
    }
    ......
    ......
}

I hope it will help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜