iOS-UIAlertController弹出延迟(UIAlertController弹出缓慢,tableViewCell点击时背景颜色改变)

前言

今天有个小伙伴问我,他在给tableViewCell添加选中事件的时候,调用UIAlertController,但是UIAlertController弹出有点延迟,不知道什么原因,我也找了好久。

经过我测试我发现了一种方法可以解决;具体原因我认为是runloop没有及时更新UI。

解决办法

方法一:

[self presentViewController:alertController animated:YES completion:nil];

改为下面的方法:

dispatch_async(dispatch_get_main_queue(), ^{
    [self presentViewController: alertController animated: YES completion: nil];
});

 

方法二:

一部分小伙伴把tableViewCell的selectionStyle设成了UITableViewCellSelectionStyleNone,只需要将这个设置去掉就好或者设置成UITableViewCellSelectionStyleDefault就好;

说明

针对第二种修改方法;

在这我就多说一下,很多小伙伴设置selectionStyle=UITableViewCellSelectionStyleNone,是因为cell有个选中背景颜色,会影响cell上面控件的颜色。我们可以这样设置,可以先设置cell的选中背景视图如下:

UIView *cellBlack = [[UIView alloc] initWithFrame:cell.frame];
        cellBlack.backgroundColor = [UIColor clearColor];
        cell.selectedBackgroundView = cellBlack;

然后在cell里面设置:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    UIColor *originColor = self.leftMessage.backView.backgroundColor;
    [super setSelected:selected animated:animated];
    self.leftMessage.backView.backgroundColor = originColor;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    UIColor *originColor = self.leftMessage.backView.backgroundColor;
    [super setHighlighted:highlighted animated:animated];
    self.leftMessage.backView.backgroundColor = originColor;
}

 

希望对你有所帮助!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值