私の目標は、サーバーから取得したデータが取り込まれたセルのリストを表示することです。そして、ユーザーが下にスクロールすると、簡単に言えば、「さらに読み込んでいます」という表のセルが表示され、より多くのセルにデータが入力されると消えます。
これを行うための関連セクションは次のとおりです。
- (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 テーブル セルしか表示されません。なんで?
ありがとう!