2016-07-22 3 views
-2

Я пробовал несколько способов исправить этот устаревший код, но ничего не помог мне. Я новичок в Objective C и iOS, помогите мне исправить это ... Он отлично работает в iOS8, но не в iOS9 ..UIAlertView устарел, как я могу исправить этот код как UIAlertController? Я не могу понять, как использовать оператор switch в UIAlertController

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    [super alertView:alertView clickedButtonAtIndex:buttonIndex]; 

    if (buttonIndex) 
    { 
     switch (alertView.tag) 
     { 
      case kAccessAddressBook: 
      { 
       [self displayFindFriendView:[NSNumber numberWithInteger: CS_CONTACTS ]]; 
      } 
       break; 
      case kFindFriendEmail: 
      { 

      } 
       break; 
      case kLogout: 
      { 
       // Hit Logout API 
       [self userLogout]; 
      } 
       break; 
      case kClearSearchHistory: 
      { 
       // Clear Search History Data base. 
       [[CSCoreDataHandler sharedInstance] deleteManagedObjectsInModel:@"CSRecentSearch"]; 

      } 
       break; 
      default: 
       break; 
     } 
    } 
} 
+0

эй вы хотите, чтобы эти значения, чтобы указать оповещения, которое верно в случае (переключатель) я прав .. –

+0

да вот правый –

+0

UIAlertAction * DefaultAction; Вы можете указать это и каждый, когда ваше значение изменится в случае, установленном defaultAction –

ответ

1

AlertView является depricated в IOS 8.So мы должны использовать UIAlertController.

UIAlertController * alert = [UIAlertController 
      alertControllerWithTitle:@"Title" 
          message:@"Message" 
         preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction *actionAccessAddressbook = [UIAlertAction 
        actionWithTitle:@"Access" 
           style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction * action) { 
         [self displayFindFriendView:[NSNumber numberWithInteger: CS_CONTACTS ]]; 
          }]; 

UIAlertAction *actionFindFriendEmail = [UIAlertAction 
         actionWithTitle:@"Find Friend Email" 
            style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) { 
            //...Do your stuff here 
           }]; 

UIAlertAction *actionLogout = [UIAlertAction 
         actionWithTitle:@"Logout" 
            style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) { 
            [self userLogout]; 
           }]; 
UIAlertAction *actionClearSearchHistory = [UIAlertAction 
         actionWithTitle:@"ClearSearchHistory" 
            style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) { 
            [[CSCoreDataHandler sharedInstance] deleteManagedObjectsInModel:@"CSRecentSearch"]; 
           }]; 


[alert addAction:actionAccessAddressbook]; 
[alert addAction:actionFindFriendEmail]; 
[alert addAction:actionLogout]; 
[alert addAction:actionClearSearchHistory]; 

[self presentViewController:alert animated:YES completion:nil]; 
2
-(void)alert 
{ 
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
                    message:@"This is an alert." 
                  preferredStyle:UIAlertControllerStyleAlert]; 
    if (buttonIndex) 
    { 
     switch (alertView.tag) 
     { 
      case kAccessAddressBook: 
      { 


       defaultAction = [UIAlertAction actionWithTitle:[self displayFindFriendView:[NSNumber numberWithInteger: CS_CONTACTS ]]; style:UIAlertActionStyleDefault 
                 handler:^(UIAlertAction * action) {}]; 
      } 
       break; 
      case kFindFriendEmail: 
      { 

      } 
       break; 
      case kLogout: 
      { 
       // Hit Logout API 
       [self userLogout]; 
      } 
       break; 
      case kClearSearchHistory: 
      { 
       // Clear Search History Data base. 
       [[CSCoreDataHandler sharedInstance] deleteManagedObjectsInModel:@"CSRecentSearch"]; 

       defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
                 handler:^(UIAlertAction * action) {}]; 

      } 
       break; 
      default: 
       break; 
     } 
    } 



    [alert addAction:defaultAction]; 

    [self presentViewController:alert animated:YES completion:nil]; 
} 
Смежные вопросы