UIAlertView Button Event Problem
alright so i have a small problem here, i have this here.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//YES clicked ...do your action
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
else if (buttonIndex == 1)
{
//NO clicked
return;
}
}
This Allows me to capture events triggered from UIAlertView Buttons but i have assigned it a value and on the same page i need another value to be assigned to that class so:
if(buttonIndex == 2){//Proceed}
开发者_如何学Goi mainly want it so that when the button is pushed on my second alert it will go back to the processes it was doing and not proceed with the event of (buttonIndex == 0).
So Does anyone know Where i could start?
Just store a reference in you .h
file of the 2 UIAlertView
's, and then do a check. For instance, in your .h
file:
UIAlertView * alertView1; UIAlertView * alertView2;
In your .m
file, set up your UIAlertView
's in you viewDidLoad
method, and change the alertView:clickedButtonAtIndex:
method to:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; {
if (alertView == alertView1) {
// Do what you want the alertView1 to do here.
if (buttonIndex == 0) {
//YES clicked ...do your action
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
else if (buttonIndex == 1) {
}// etc.
}
else if (alertView == alertView2) {
// Do what you want the alertView2 to do here.
}
}
Hope that Helps!
Something else you can do is use the alertView tag in case you have multiple alertviews in your app. For instance, you could do something like this:
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Title" message:@"AThe message." delegate:self cancelButtonTitle:@"button 1" otherButtonTitles: @"button 2", nil];
alert1.tag = 0;
[alert1 show];
[alert1 release];
Then in your delegate method, simply put the following if clause:
if (alertView == alertView1)
before your code above.
If you don't figure this out, you could place a counter in the program that counts the number of times the alertview had been triggered, and then act upon that value.
精彩评论