iOS8提供了UIAlertController控件,用起來真是方便,特別是對選擇項的點擊事件可以直接在其block里面執行,不用像之前的在其委托對象中處理了。但是有的時候你也許會碰到這一場景,你的個人頭像是放在cell里面的,為了擴大頭像的點擊范圍,選擇了點擊cell即可調查選擇照片或拍照的選項(這里肯定會首選UIAlertController來實現了),發現選擇彈出框老是會有延遲彈出的情況,有的時候不明顯,有的時候比較明顯,如果你碰到了這一場景原則就在于你對cell的selectionStyle設置成了UITableViewCellSelectionStyleNone,影響了彈出框的響應時間.
方法1:
只要將其改成:UITableViewCellSelectionStyleDefault即可。
方法2
在主線程更新UI:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"刪除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:deleteAction];
[alert addAction:cancelAction];
/**< 主線程更新UI,不然會出現延遲彈窗 */
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf presentViewController:alert animated:YES completion:nil];
});