如果验证了警报,如何显示新的视图控制器? (objective c)

How to show a new view controller if the alert is validated? (objective c)

如果警报被验证,我想更改视图控制器而不是按钮,但我不知道该怎么做。我使用 cocoa pod 作为通知(只是因为设计很漂亮)。欢迎每一个答案!

- (IBAction)changeTheme:(UIButton *)sender {

    // for changing view controller
    [UIView animateKeyframesWithDuration:1.0 delay:0 options:0 animations:^{
        changeTheme.transform = CGAffineTransformMakeScale(2, 2);
    } completion:^(BOOL finished) {

        // init alert with options
        SCLAlertView *changeThemeNotification = [[SCLAlertView alloc] init];

        // to sport
        [changeThemeNotification addButton:@"change to sport" validationBlock:^BOOL{
            BOOL passedValidation = true;
            return passedValidation;
        } actionBlock:^{

        }];
        // to food
        [changeThemeNotification addButton:@"change to food" validationBlock:^BOOL{
            BOOL passedValidation = true;
             return passedValidation;
        } actionBlock:^{
            [self.view setBackgroundColor:[UIColor blackColor]];
        }];

        // to animal
         [changeThemeNotification addButton:@"change to animal" validationBlock:^BOOL{
             BOOL passedValidation = true;
             return passedValidation;
         } actionBlock:^{
             [self.view setBackgroundColor:[UIColor greenColor]];
         }];

          // else (message & options)
        [changeThemeNotification showCustom:self image:nil color:[self.colorWheel randomColor] title:@"Test" subTitle:@"This is a test notification for the navigation." closeButtonTitle:@"stay" duration:0.0f];
        changeThemeNotification.hideAnimationType = SlideOutToBottom;
        changeThemeNotification.shouldDismissOnTapOutside = YES;
        changeThemeNotification.soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/url_to_sound.mp3", [[NSBundle mainBundle] resourcePath]]];

    }];
}

以下代码会有所帮助:

检查 iOS 版本:

#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 

要显示警报视图:

if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                        message:@"your message"
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"OK", nil];
        [alert show];
    }

    else
    {
        UIAlertController *alertController = [UIAlertController
                                              alertControllerWithTitle:@""
                                              message:@"You message..."
                                              preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction      *okAction = [UIAlertAction
                                        actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                                        style:UIAlertActionStyleDefault
                                        handler:^(UIAlertAction *action)
                                        {
                                           [self performSegueWithIdentifier:@"yourSegueName" sender:self];
                                        }];


        [alertController addAction:okAction];
        [self presentViewController:alertController animated:YES completion:nil];
    }

还使用以下代码处理 "ok" 按钮 iOS <8.0.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex                                   {
    if (buttonIndex == 0)
    {
        [self performSegueWithIdentifier:@"yourSegueName" sender:self];
    }
    else
    {


    }
}

试试这个

  SCLAlertView *changeThemeNotification = [[SCLAlertView alloc] init];

  [changeThemeNotification addButton:@"change to sport" validationBlock:^BOOL{
        BOOL passedValidation = true;
        return passedValidation;
  } actionBlock:^{
      [self performSegueWithIdentifier:@"yourSegueName" sender:self];

  }];