2017-01-19 64 views
0

這些已被棄用,但我沒有找到解決方案來改善它:actionSheet:didDismissWithButtonIndex:已在iOS 8.3中棄用。我現在必須使用什麼新方法?

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

非常感謝。

+0

⌘-點擊'UIActionSheet'。在那裏你會發現如何更換它的建議。 – vadian

回答

1

您可以使用UIAlerControllerUIActionSheetiOS 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

謝謝。

+0

非常感謝,它工作得很好:) – Claudio

相關問題