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

1.前言
今天有个小伙伴问我,他在给tableViewCell添加选中事件的时候,调用UIAlertController,但是UIAlertController弹出有点延迟,不知道什么原因,我也找了好久。
经过我测试我发现了一种方法可以解决;具体原因我认为是runloop没有及时更新UI。
2.解决办法
方法一:

<pre>[selfpresentViewController:AlertControlleranimated:YEScompletion:nil];
//改为下面的方法:
dispatch_async(dispatch_get_main_queue(), ^{
[selfpresentViewController: AlertControlleranimated: YEScompletion:nil];
});</pre>

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

3.说明
针对第二种修改方法;
在这我就多说一下,很多小伙伴设置selectionStyle=UITableViewCellSelectionStyleNone,是因为cell有个选中背景颜色,会影响cell上面控件的颜色。我们可以这样设置,可以先设置cell的选中背景视图如下:
<pre>UIView *cellBlack = [[UIView alloc] initWithFrame:cell.frame];
cellBlack.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = cellBlack; </pre>
然后在cell里面设置:
<pre>- (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;
    } </pre>

转载自:http://blog.csdn.net/u014220518/article/details/55095598

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容