iOS-UIAlertController弹出延迟(UIAlertController弹出缓慢,tableViewCell点击时背景颜色改变)
2017-02-14 10:47
696 查看
1.前言
今天有个小伙伴问我,他在给tableViewCell添加选中事件的时候,调用UIAlertController,但是UIAlertController弹出有点延迟,不知道什么原因,我也找了好久。经过我测试我发现了一种方法可以解决;具体原因我认为是runloop没有及时更新UI。
2.解决办法
方法一:[selfpresentViewController:AlertControlleranimated:YEScompletion:nil];
改为下面的方法:
dispatch_async(dispatch_get_main_queue(), ^{
[selfpresentViewController: AlertControlleranimated:
YEScompletion:
nil];
});
方法二:
一部分小伙伴把tableViewCell的selectionStyle设成了UITableViewCellSelectionStyleNone,只需要将这个设置去掉就好或者设置成UITableViewCellSelectionStyleDefault就好;
3.说明
针对第二种修改方法;在这我就多说一下,很多小伙伴设置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; }
希望对你有所帮助!
相关文章推荐
- iOS 点击cell改变背景颜色或者图片&&cell中其他部分取消高亮显示
- iOS cell添加点击时改变字体的颜色及背景
- iOS 自定义cell点击后里面的子控件背景颜色被改变解决办法
- IOS总结_无需自己定义UITabbar也可改变UITabbarController的背景和点击和的颜色
- iOS 自定义Tabbar 改变点击背景颜色
- iOS: UITableViewCell点击效果下, 防止子控件背景颜色改变
- iOS关于cell点击更换背景颜色
- iOS 开发 解决UITableViewcell单选动态改变cell文字和背景颜色的功能,且第一次默认选择第一个cell
- tableview 点击cell改变cell中的label.text的字体颜色,cell复用出现问题的解决方案
- ios点击改变uiview背景颜色
- 使用Runtime解决 cell 点击时子视图改变背景颜色的问题
- iOS每日一记之---------改变Btn点击时的背景颜色
- IOS总结_无需自定义UITabbar也可改变UITabbarController的背景和点击和的颜色
- iOS点击UITableView的cell,弹出UIAlertController有时会出现延迟
- iOS: UITableViewCell点击效果下, 防止子控件背景颜色改变
- iOS UITextField位置随输入键盘动态改变 点击背景键盘消失
- Android LinearLayout 点击背景颜色改变
- 【iOS开发-39】为什么按钮点击时背景图片颜色灰蒙蒙的?与按钮的Type属性有关
- android 点击右上角加号,弹出下拉菜单的分割线背景颜色设置解决方案
- tableview 点击cell改变cell中的label.text的字体颜色,cell复用出现问题的解决方案2