答えのための@trungducのおかげで、私は人々がそれが有用であることを期待して、これに完成した解決策を投稿しています。すでに表示されている表の描画セルを停止するには、テーブルに表示されている最大のインデックスであるlastCellDisplayedIndex
を追跡する変数を実装する必要があります。 @ trungducの答えでは、彼は- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
メソッドにこの変数を入れましたが、これによっていくつかのセルが再描画されるいくつかのエラーが発生することがわかりました。私はcellForRow
とcellWillDisplay
メソッドの違いを読んでいました。アニメーションを配置するのに最適な場所のようでした。cellWillDisplay
はセルが初期化されていて、明らかに、UIの操作をアニメーション!)。
このメソッドは、次のようになります。
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
lastCellDisplayedIndex = MAX(indexPath.row, lastCellDisplayedIndex);
NSLog(@"lastCellDisplayedIndex = %ld, indexPath for Cell = %ld", lastCellDisplayedIndex, indexPath.row);
if (lastCellDisplayedIndex <= indexPath.row){
cell.alpha = 0;
[UIView animateWithDuration:2.0 animations:^(){
cell.alpha = 1;
}];
if (lastCellDisplayedIndex == totalCellsToDisplay - 1){
NSLog(@"END OF TABLE ANIMATIONS!");
lastCellDisplayedIndex = totalCellsToDisplay + 1;
}
}
else {
cell.alpha = 1;
}
}
この方法では、ほとんどすべてを処理します。最初にlastCellDisplayedIndex
の値を、テーブルが見た最大インデックスの値に変更します。次に、処理しているセルをアニメートするか、そのまま放置するかを決定します。私はまた、totalCellsToDisplay
があなたのテーブルのデータソース配列として作用する、(種類の)ガード変数を追加する必要がありました: -
(NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return totalCellsToDisplay;
}
は、だからあなたの本当のアプリであなたの代わりに私が
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return yourTableDataArray.count;
}
理由を持っているでしょうあなたはこのコードを持っている場合、描画されているセルの最大数は、チェック:
lastCellDisplayedIndex = MAX(indexPath.row, lastCellDisplayedIndex);
if (lastCellDisplayedIndex <= indexPath.row){}
、最大のインデックスは、最終的な細胞よりも高い行くことは決してありませんので、この細胞は、すべてのタイムを生き返らされますあなたは上下にスクロールします。 indexPath
= the total cells - 1
(ゼロインデックスのため)を修正するには、lastCellDisplayedIndex
の値をバンプして、それ以上のセルが描画されないようにします。
最後に、テーブルが最初に描画するセルの数を解決する必要があります。私はこれがどういう仕組みかはっきりしていませんが、私のテストでは15個以上のセルが返されます(15個を返した場合)。とにかく私はずば抜けたロードアニメーションを実装し、アニメーション機能をロードすることでこの問題を解決しました。
- (void)tableFadeInAnimation {
[_myTable reloadData];
NSArray<UITableViewCell *> *cells = _myTable.visibleCells;
NSInteger index = 0;
for (UITableViewCell * m in cells){
UITableViewCell *cell = m;
cell.alpha = 0;
[UIView animateWithDuration:0.5 delay:0.25 * index options:0 animations:^(){
cell.alpha = 1;
} completion:^(BOOL finished){
lastCellDisplayedIndex = _myTable.visibleCells.count;
NSLog(@"Table Animation Finished, lastCellDisplayed Index = %ld", lastCellDisplayedIndex);
}];
NSLog(@"end of table animation");
index += 1;
}
}
Iが表示されている細胞の数に等しいlastCellDisplayed
の値を設定する機能の完了ブロックを使用します。これで、テーブルビューはすべての新しいセルをアニメーション化します。
これは役に立っています。回答は@trungducにお寄せください!
'willDisplayCell'は、再利用されたセルに対して呼び出されます。同じ問題。 – Connor
@Connorこれは正しいです。私は実際に 'willDisplayCell'を試してみましたが、' cellForIndexPath'のコードを持っているのと同じように動作しました。 – Axemasta
@Axemasta私の答えはどうですか; – trungduc