代码之家  ›  专栏  ›  技术社区  ›  gabaum10

iPhone加载更多TableViewCell

  •  2
  • gabaum10  · 技术社区  · 15 年前

    所以我有一个设计问题要问你。基本上,我有一个应用程序,当应用程序加载时,我从服务器获取20个项目,并将它们显示在表视图中。我还有一个显示在最后一个单元格中的加载表单元格。我要做的是,当该单元格出现时,加载接下来的20个项目,并将它们添加到列表中,然后重新加载表。

    你们对此有什么建议?当手机出现时,我应该自动关闭请求吗?或者我应该等别的事情来做吗?如有任何意见,我们将不胜感激。谢谢!

    2 回复  |  直到 15 年前
        1
  •  3
  •   deanWombourne    15 年前

    就我个人而言,我会在手机出现时立即取消请求。事实上,我会考虑在牢房出现之前启动请求——在15号牢房附近?这样,用户在显示加载单元时等待的时间就更少了。

    然而,这完全取决于您的数据集有多大——如果要获得接下来的20行数据量很大,我会放一些类似“按这里获得更多结果”的东西,然后等待用户的输入触发请求。

    找出哪种用户体验最好的最好方法是快速进行用户测试——让可能是您客户的人测试应用程序,看看他们最喜欢哪种应用程序。看看像你这样的应用程序——它们是做什么的——如果它们为你的客户树立了先例,也许你应该试着遵循它?

        2
  •  2
  •   jfalexvijay    15 年前

    您可以使用以下测试代码;

    - (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;
        }
        ......
        ......
    }
    

    我希望它能帮助你。