actionSheet:didDismissWithButtonIndex:在iOS 8.3中已弃用。我现在必须使用的新方法是什么?

时间:2017-01-19 12:18:31

标签: ios objective-c xcode uiactionsheet dismiss

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

 [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:

非常感谢。

2 个答案:

答案 0 :(得分:1)

来自Apple的website,显然你应该使用UIAlertController

答案 1 :(得分:1)

您可以使用UIAlerController UIActionSheet iOS之后弃用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替换map.invalidateSize()

感谢。