如果用actionSheet问用户选项,然后选择做啥
UIActionSheet *actionSheet= [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相片库选取", nil];
[actionSheet showInView:self.view];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
selectedIndex = buttonIndex;
if (selectedIndex == 0) {
[self addCarema];
}else if (selectedIndex == 1){
[self openPicLibrary];
}
}
openPicLibrary唤不起窗体,会有错误
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:^{
}];
比如类似错误
Warning: Attempt to present on xxxx which is already presenting (null)
参考解决方式:
引用
I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController until the next iteration of the runloop, by doing this:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self openPhotoPicker:sourceType];
}];
本例的解决办法是:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
selectedIndex = buttonIndex;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if (selectedIndex == 0) {
[self addCarema];
}else if (selectedIndex == 1){
[self openPicLibrary];
}
}];
}
或者是记下点击的index,在动画结束的时候处理:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (selectedIndex == 0) {
[self addCarema];
}else if (selectedIndex == 1){
[self openPicLibrary];
}
}
iOS8开发弹不出窗体解决办法
最新推荐文章于 2021-05-28 20:17:11 发布
在ios8应用开发的时候出现窗体弹不出的现象,提示错误:Warning: Attempt to present on xxxx which is already presenting (null),现在来看解决方法。