1

私の目標は、サーバーから取得したデータが取り込まれたセルのリストを表示することです。そして、ユーザーが下にスクロールすると、簡単に言えば、「さらに読み込んでいます」という表のセルが表示され、より多くのセルにデータが入力されると消えます。

これを行うための関連セクションは次のとおりです。

 - (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 は機能しません。データは表示されますが、BLANK テーブル セルしか表示されません。なんで?

ありがとう!

4

2 に答える 2

1

問題が発生したかどうかはわかりませんが、Interface Builder でカスタム セルを作成する場合は、クラスではなく Nib を登録する必要があります。

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

そして、すべてのセルに対して呼び出される cellForRowAtIndexPath ではなく、ViewDidLoad で実行してください :-)

于 2015-03-06T10:05:55.027 に答える