iphone – problem in UIAlet – Education Career Blog

I am create my first iphone app however facing lots of problems now.. I am trying to use an alert window which has options of Yes and No. WHen i click on no it should remain on the same screen however when i click Yes it should take me to another screen but i am not able to do the Yes part. My code looks like this..

-(IBAction)buttonPressedid)sender
{
NSString *TITLE = NSString alloc initWithFormat: @"Do you want to add the ingredient to your Grocery list";
UIAlertView *alert = UIAlertView alloc initWithTitle:@"Message" 
message:TITLE 
delegate:nil
cancelButtonTitle:@"No" 
otherButtonTitles:@"YES",nil;

So when i click yes it should take me to another screen. How should i do that?

Pls help…

,

you need UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

for more detail read following tutorial

http://mobile.tutsplus.com/tutorials/iphone/uialertview/

,

UIAlertView *alert = UIAlertView alloc initWithTitle:@”Game Over” message:nil delegate:self cancelButtonTitle:@”Quit” otherButtonTitles:@”Restart”,nil;
alert.tag = 1;
alert show;
alert release;

pragma mark AlertView delegate methods

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 3) {
    if (buttonIndex == 0) {
    exit(0);
    }
    else {
    UIView beginAnimations:nil context:NULL;
    UIView setAnimationDuration:1.5;
    UIView setAnimationDelegate:self;
    UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES;
    self viewWillAppear:YES;
    UIView commitAnimations;

        appDelegate.winningAmount = nil;
        encylCount = 0;
        googleCount = 0;
        mGoogleButton.userInteractionEnabled = YES;
        mEncyclopediaButton.userInteractionEnabled = YES;
    }
    

    }

}

Leave a Comment