Warning: Attempt to present on xxx which is already presenti
阿新 • • 發佈:2019-02-01
iOS8中使用 UIActionSheet 跳轉到相機出錯. UIActionSheet : UIView
// UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead
比如在彈出的actionsheet中選擇從相簿選擇圖片或者拍照,之後彈出UIImagePickerController進行選擇。
在iOS8以前的方法裡,直接在Click的委託事件裡處理就好了,
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
但是在iOS8,系統會丟擲警告,並且取消彈出ImagePicker行為。
Warning: Attempt to present <UIImagePickerController: 0x15c8a0000> on <WCProfileController: 0x15c53cc50> which is already presenting (null)
原因在警告裡說得比較明白了,因為已經有actionsheet存在了,不能present新的。此時我們選擇新的委託方法didDismissWithButtonIndex方法即可。
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;