TobiasPratt
TobiasPratt

Reputation: 3

Alerts and if statements - Xcode

I'm trying to trigger an alert with an if statement. but the code im using wont do what i want.

This is one attempt at triggering the alert

-(Void)ShowAlert
     if (mainInt == 120) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"Message"
            delegate:nil cancelButtonTitle:@"Dismiss"otherButtonTitles:nil, nil];
        [alert show];
}

i have declared 'ShowAlert' in the .h file as -(void)ShowAlert just under my -(IBAction) declares.

But still no alert when ran in simulator. Any help with this would be greatly appreciated!!

THANKS

(I'm am using Xcode 4.6.2)

Upvotes: 0

Views: 268

Answers (1)

EFE
EFE

Reputation: 3752

Maybe if (mainInt == 120) is never true.

I would try with an ELSE if i were you. And log whole process about what's going on like this:

-(void)ShowAlert{
     if (mainInt == 120){
        NSLog(@"TRUE i should see the alertview! , mainInt = %i",mainInt);
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"Message"
            delegate:nil cancelButtonTitle:@"Dismiss"otherButtonTitles:nil, nil];
        [alert show];
     }else{
     NSLog(@"FALSE , mainInt = %i",mainInt);
     }
}

Upvotes: 1

Related Questions