gpt4 book ai didi

ios - 按下 actionSheet 按钮后的警告消息

转载 作者:行者123 更新时间:2023-11-29 02:46:44 29 4
gpt4 key购买 nike

我是 iOS 开发的新手,遇到了一个我似乎无法找到解决方案的错误。我到处寻找解决方案,但也许是我的新奇阻碍了我看到问题。

日志中打印的确切警告是:

在演示或关闭正在进行时尝试从 View Controller <_UIAlertShimPresentingViewController: 0x7aaa4b90> 关闭!

它在我触摸 actionSheet 上的按钮后立即发生。

代码如下:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

if (buttonIndex == 0) {

picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentViewController:picker animated:YES completion:nil];
}
else if (buttonIndex == 1) {

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:picker animated:YES completion:nil];

}
else if (buttonIndex == 2) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

[self presentViewController:picker animated:YES completion:nil];

}

} else {

if (buttonIndex == 0) {

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


[self presentViewController:picker animated:NO completion:NULL];


}
else if (buttonIndex == 1) {

picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

[self presentViewController:picker animated:YES completion:NULL];


}


}
}

actionSheet 的实现,我将 IBAction 连接到位于 .xib 文件中的工具栏按钮。

   - (IBAction)addImage:(id)sender {

UIActionSheet *popUpSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles: nil];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

[popUpSheet addButtonWithTitle:@"Camera"];
[popUpSheet addButtonWithTitle:@"Photo Library"];
[popUpSheet addButtonWithTitle:@"Camera Roll"];

[popUpSheet addButtonWithTitle:@"Cancel"];

popUpSheet.cancelButtonIndex = popUpSheet.numberOfButtons-1;

} else {

[popUpSheet addButtonWithTitle:@"Photo Library"];
[popUpSheet addButtonWithTitle:@"Camera Roll"];

[popUpSheet addButtonWithTitle:@"Cancel"];

popUpSheet.cancelButtonIndex = popUpSheet.numberOfButtons-1;

}

[popUpSheet showFromBarButtonItem: self.toolbarItems[0] animated:YES]; }

据我所知,一切都已正确委派:

DetailViewController.m

@interface DetailViewController () < UINavigationControllerDelegate, UIImagePickerControllerDelegate >

DetailViewController.h

@interface DetailViewController : UIViewController <UIActionSheetDelegate>

任何见解都将不胜感激并且非常有帮助。

最佳答案

您的代码看起来是正确的。尝试使用:

actionSheet:didDismissWithButtonIndex:

方法。它在动画结束后发送给代理。希望对您有所帮助。

关于ios - 按下 actionSheet 按钮后的警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25024119/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com