dequeueReusableCellWithIdentifier导致空白表单元格 [英] dequeueReusableCellWithIdentifier causes blank table cell

查看:88
本文介绍了dequeueReusableCellWithIdentifier导致空白表单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是显示由我从服务器下拉的某些数据填充的单元格列表.当用户向下滚动时,我希望有一个简短的表单元格,上面写着"Loading More",然后随着数据填充更多单元格而消失.

My goal is to display a list of cells that are populated by some data I pull down from a server. And as the user scrolls down I would like there to be, briefly, a table cell that says "Loading More", and then goes away as more cells are filled in with data.

以下是执行此操作的相关部分:

Here are the relevant sections to do this:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

   [tableView registerClass:[CGSitesCell class] forCellReuseIdentifier:cellIdentifier];
   // Option 1:   CGSitesCell *cell = [[CGSitesCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
   // Option 2:   CGSitesCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
   //(Still Option 2):  
   //if(cell == nil){
   //      cell = [[CGSitesCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
   if(backupsArray.count !=0){
       //if we not on the last row
      if (indexPath.row < backupsArray.count) {
             [cell.textLabel setText:someData];
      }else{
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                   reuseIdentifier:cellIdentifier];
       [cell.textLabel setText:@"Load More"];
       return cell;
      }
   return cell;
 }

这就是我难过的地方:选项1起作用.我在底部看到要查看的数据和加载更多".但是,选项2不起作用!我看到了数据,但只看到了一个空白表单元格.为什么?

Here is what has me stumped: Option 1 works. I see the data I want to see and the Load More at the bottom. However, Option 2 does not work! I see the data, but I only see a BLANK table cell. Why?

谢谢!

推荐答案

我遇到了您的问题,不知道您是否发现了问题,但是如果您使用Interface Builder构建自定义单元,则应该注册Nib,而不是课:

I came cross you question and dont know if you found the problem, but if you custom cell is built with Interface Builder then you should register the Nib, not the class:

    [self.tableView registerNib:[UINib nibWithNibName:@"CGSitesCell" bundle:nil] forCellReuseIdentifier:@"CGSitesCellIdentifier"];

请在ViewDidLoad中执行此操作,而不是在对所有单元格都调用的cellForRowAtIndexPath中进行操作:-)

And please do it in ViewDidLoad, not in cellForRowAtIndexPath which is called for all your cells :-)

这篇关于dequeueReusableCellWithIdentifier导致空白表单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆