如何重新加载和动画一个UITableView单元格/行?

时间:2011-03-24 11:51:03

标签: objective-c cocoa-touch uitableview animation

如何重新加载并为一个单元格/行设置动画? 现在我下载一些文件。每次文件下载完成后,我都会调用它完成的委托并调用[tableview reload]。 但随后整个表重新加载。我怎样才能为桌子设置动画,使其不会闪烁。例如淡化效果等。

迎接Max

6 个答案:

答案 0 :(得分:182)

使用以下UITableView实例方法:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

您必须指定要重新加载的NSArray NSIndexPaths。如果你只想重新加载。如果您只想重新加载一个单元格,那么您可以提供只包含一个NSArray的{​​{1}}。例如:

NSIndexPath

您可以查看NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:3 inSection:0]; NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil]; [myUITableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone]; 枚举,了解动画行刷新的所有可能方法。如果您不想要任何动画,则可以使用值UITableViewRowAnimation,如示例所示。

重新加载特定行比仅仅获取您想要的动画效果更有优势。您还可以获得巨大的性能提升,因为只有您真正需要重新加载的单元才能刷新,重新定位和重新绘制数据。根据单元格的复杂程度,每次刷新单元格时都会产生相当大的开销,因此缩小所做的刷新量是必要的优化,应尽可能使用。

答案 1 :(得分:3)

如果您只需要更新tableview单元格中的文本..

UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];

cell.textLabel.text = [NSString stringWithFormat:@"%i", (int)_targetMaxDistanceSlider.value];

答案 2 :(得分:1)

快速4和5

对于TableView

let index = IndexPath(row: 0, section: 0)
tableView.reloadRows(at: [index], with: .automatic)

对于CollectionView

let index = IndexPath(item: 2, section: 0)
collectionView.reloadItems(at: [index])

答案 3 :(得分:0)

Apple Document  用新语法完成它

$inFile = 'file.exe';
$outFile = 'php://output';

$inHandle = fopen($inFile, 'r');
$outHandle = fopen($outFile, 'w');

stream_filter_append($inHandle, 'convert.base64-decode');

stream_copy_to_stream($inHandle , $outHandle);
fclose($inHandle );
fclose($outHandle);

答案 4 :(得分:0)

要在给定tableView的{​​{1}}中重新加载特定单元格,您需要创建indexPaths数组,然后调用函数indexPathsreloadRowsAtIndexPaths

以下是示例:

夫特:

tableView

目标C:

let indexPathsToReload = [indexPath1, indexPath2, indexPath3]
tableView.reloadRowsAtIndexPaths(indexPathsToReload, withRowAnimation: .None)

NSArray *indexPaths = @[indexPath1, indexPath2, indexPath3];
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];

答案 5 :(得分:0)

快速

您可以使用

let selectedIndexPath = IndexPath(item:0 , section: 0)
self.tableView.reloadRows(at: [selectedIndexPath], with: .none)

以便重新加载特定的单元格。

相关问题