2017-01-19 19 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

⌘-click на 'UIActionSheet'. Там вы найдете предложение о том, как его заменить. – vadian

ответ

1

Вы можете использовать UIAlerController в UIActionSheet осуждается после iOS 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