Commit c24f3e80 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Fix crash when updating UITableViewCells in iOS 12

In iOS 12, calling
[UITableView reloadRowsAtIndexPaths:withRowAnimation:] inside the
completion handler of [UITableView performBatchUpdates:completion:] may
trigger a crash.

The workaround is to get UITableViewCell via
[UITableView cellForRowAtIndexPath:] and then reconfigure the cell
directly. This will lose the built-in animation from UIKit when cells
are updated.

Once iOS 12 is deprecated, remove this workaround and use
[UITableView reloadRowsAtIndexPaths:withRowAnimation:].

Bug: 1028074
Change-Id: Ida4fbf94f31b7b00cb9052177f3350c60ae9e4e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1936487Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719135}
parent 18bb01bb
......@@ -522,9 +522,26 @@ const char kUmaSelectDefaultSearchEngine[] =
} else {
engineItem.accessoryType = UITableViewCellAccessoryNone;
}
// This function might be called inside the completion handler of
// [UITableView performBatchUpdates:completion:], which will cause a crash
// in iOS 12.
// TODO(crbug.com/1028546): Remove this workaround once iOS 12 is
// deprecated.
if (@available(iOS 13, *)) {
} else {
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell) {
TableViewCell* tableViewCell =
base::mac::ObjCCastStrict<TableViewCell>(cell);
[item configureCell:tableViewCell withStyler:self.styler];
}
}
}
if (@available(iOS 13, *)) {
[self.tableView reloadRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationAutomatic];
}
[self.tableView reloadRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment