1.前言
今天有個(gè)小伙伴問(wèn)我赚窃,他在給tableViewCell添加選中事件的時(shí)候,調(diào)用UIAlertController岔激,但是UIAlertController彈出有點(diǎn)延遲勒极,不知道什么原因,我也找了好久虑鼎。
經(jīng)過(guò)我測(cè)試我發(fā)現(xiàn)了一種方法可以解決辱匿;具體原因我認(rèn)為是runloop沒(méi)有及時(shí)更新UI。
2.解決辦法
方法一:
<pre>[selfpresentViewController:AlertControlleranimated:YEScompletion:nil];
//改為下面的方法:
dispatch_async(dispatch_get_main_queue(), ^{
[selfpresentViewController: AlertControlleranimated: YEScompletion:nil];
});</pre>
方法二:
一部分小伙伴把tableViewCell的selectionStyle設(shè)成了UITableViewCellSelectionStyleNone炫彩,只需要將這個(gè)設(shè)置去掉就好或者設(shè)置成UITableViewCellSelectionStyleDefault就好匾七;
3.說(shuō)明
針對(duì)第二種修改方法;
在這我就多說(shuō)一下媒楼,很多小伙伴設(shè)置selectionStyle=UITableViewCellSelectionStyleNone乐尊,是因?yàn)閏ell有個(gè)選中背景顏色,會(huì)影響cell上面控件的顏色划址。我們可以這樣設(shè)置扔嵌,可以先設(shè)置cell的選中背景視圖如下:
<pre>UIView *cellBlack = [[UIView alloc] initWithFrame:cell.frame];
cellBlack.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = cellBlack; </pre>
然后在cell里面設(shè)置:
<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>
轉(zhuǎn)載自:http://blog.csdn.net/u014220518/article/details/55095598