0

instead of a button i'd like to change the view controller if a alert is validated but i've no idea how to do is. I use a cocoa pod for the notification (just cause the design is beautiful). every answer is welcome!

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

    }];
}

2 Answers2

0

The following code will help:

To check the iOS version:

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

To display the alert view:

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

Also use the following code to handle "ok" button for iOS <8.0.

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


    }
}
Shubham
  • 88
  • 6
  • the app crashed. idk why – Tobias Horst Jul 06 '15 at 12:31
  • 2015-07-06 14:42:52.821 FunFacts[5724:101953] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key funFactLabel.' *** First throw call stack: ... libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) – Tobias Horst Jul 06 '15 at 12:45
  • Cross-check whether the "funFactLabel" property is bind with the storyboard label. Verify binding of all the properties in the second view controller. Refer following answers:- http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key http://stackoverflow.com/questions/26353378/xcode-6-this-class-is-not-key-value-coding-compliant – Shubham Jul 06 '15 at 12:51
0

try this

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

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

  }];