开发者

opening previous/back screen in iphone clicking on leftbarbuttonitem showing alert with "ok" and "cancel"

i am working on a navigation based application.On the top of the navigation bar there is a by default back button option.i have implemented a uialertview on click event of the back button.

-(IBAction)gotolevelcontroller:(id)sender//method is declared in leftbarbuttonitem's action selector
{  
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Exit" message:@"Do You want to exit?" delegate:self cancelButtonTitle:@"OK"
                                          otherButtonTitles:@"Cancel", nil];  
    alert.delegate = self;  
    [alert show];  
    [alert release];    
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {    
    if (buttonIndex == 0)
    {
        //go to previous screen of navigation control.
            //what is code to go to previous screen
        NSLog(@"ok");
    }
    else
    {
        //r开发者_Go百科emain on same screen of navigation control
        NSLog(@"cancel");
    }
}

any suggestions? Thanks


Add this code

if (buttonIndex == 0)
{
   [self.navigationController popViewControllerAnimated:YES];
}


You are looking for the poptoviewcontroller method of the navigation controller.

[self.navigationcontroller poptoviewcontroller:<prev-viewcontroler> animated:YES/NO];


Back button pops the current viewController.

so add : [self.navigationController popViewController Animated:YES]; to buttonIndex == 0

and for cancel.. just type return;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜