2016-07-22 24 views
-2

Ich habe versucht, mehrere Möglichkeiten, um diesen veralteten Code zu beheben, aber nichts half mir, ich bin neu in Objective C und iOS bitte helfen Sie mir das beheben ... Es funktioniert gut in iOS8 aber nicht in iOS9 ..UIAlertView ist veraltet Wie kann ich diesen Code als UIAlertController reparieren? Ich kann nicht herausfinden, wie switch-Anweisung in UIAlertController verwenden

- (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

hey wollen Sie diejenigen Wert Alarm angeben, die im Fall (Switch) wahr ist, bin ich recht .. –

+0

ja das ist richtig –

+0

UIAlertAction * default; Sie können dies und jedes, wenn Ihr Wert sich ändert in der Fall setzen defaultAction –

Antwort

1

Alertview in iOS 8.So depricated ist, müssen wir UIAlertController verwenden.

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]; 
}