gpt4 book ai didi

ios - actionSheet :didDismissWithButtonIndex: is deprecated in iOS 8. 3. 我现在必须使用的新方法是什么?

转载 作者:行者123 更新时间:2023-11-28 21:14:33 25 4
gpt4 key购买 nike

这些已被弃用,但我找不到改进它的解决方案:

 [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Take Photo", nil) style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action)
{
[self actionSheet:nil didDismissWithButtonIndex:0];
}]];

和:

  [[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Take Photo", nil), NSLocalizedString(@"Photo Library", nil), nil] showInView:controller.view];

最后:

- (void)actionSheet:(__unused UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
switch (buttonIndex)
{
case 0:
{
sourceType = UIImagePickerControllerSourceTypeCamera;
break;
}
case 1:

非常感谢。

最佳答案

您可以使用 UIAlerController,因为 UIActionSheetiOS 8.3 之后被弃用。

请查看以下代码以供引用。

UIAlertController* alert = [UIAlertController
alertControllerWithTitle:nil // Must be "nil", otherwise a blank title area will appear above our two buttons
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* button0 = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
// UIAlertController will automatically dismiss the view
}];

UIAlertAction* button1 = [UIAlertAction
actionWithTitle:@"Camera"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action)
{
// The user tapped on "Camera"
}];

UIAlertAction* button2 = [UIAlertAction
actionWithTitle:@"Photo Library"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action)
{
// The user tapped on "Camera"
}];

[alert addAction:button0];
[alert addAction:button1];
[alert addAction:button2];
[self presentViewController:alert animated:YES completion:nil];

希望这会指导您进入 UIAlterController 以取代 UIActionSheet

谢谢。

关于ios - actionSheet :didDismissWithButtonIndex: is deprecated in iOS 8. 3. 我现在必须使用的新方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41741626/

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