I\'m modifying a table view cell during a call to tableView:cellForIndexPath
, but the modifications do not appear until the cell is scrolled off and then back on. I
Approach - 1 reload cell in viewWillAppear with delay mathod
func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.10, execute: {
self.tableView.reloadData() })
}
Approach - 2 Draw in GCD
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TheCorrectCellIdentifier" forIndexPath:indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(4., 4.)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = cell.bounds;
maskLayer.path = maskPath.CGPath;
cell.layer.masksToBounds = YES;
cell.layer.mask = maskLayer;
});
return cell;
}