I am new in iPhone developer,
I want to implement 2 alert view one after another, like when user press delete button, 1st alert view will ask Are you sure want to Delete ?
with two buttons yes
and no
Now, if user presses yes
, then 2nd alert view will come with message Deleted Successfully !
this alert view contains only OK
button, now on click of this OK
button i want to call one method.
and if user presses No
then nothing should happen and alert should dismiss.
Here is my code snippet,
-(void)DeletebtnCliked:(id)sender
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Are you sure want to delete ?"
message:nil delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Yes",@"No",nil];
[alertView show];
[alertView release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
UIAlertView* alertew = [[UIAlertView alloc] initWithTitle:@"Deleted Successfully !"
message:nil delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertew show];
[alertew release];
if (buttonIndex == 0)
{
[self MethodCall];
}
}
else if (buttonIndex == 1)
{
[alertView dismissWithClickedButtonIndex:1 animated:TRUE];
}
}
after writing this code i am inside Infinite loop.
Any help will be appreciated.
alertView.tag = 1;
alertew.tag = 2;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 2)
{
//Do something
}
else
{
//Do something else
}
}
Set the second alert view's delegate to nil:
UIAlertView* alertew = [[UIAlertView alloc] initWithTitle:@"Deleted Successfully !"
message:nil delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
Either use tags to tackle the situation like following or simply just set Delegate nil for the inner alertView which is inside the delegate methode so that it will never call.
-(void)DeletebtnCliked:(id)sender
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Are you sure want to delete ?"
message:nil delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Yes",@"No",nil];
alertView.tag = 1;
[alertView show];
[alertView release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0 && alertView.tag == 1)
{
UIAlertView* innerAlert = [[UIAlertView alloc] initWithTitle:@"Deleted Successfully !"
message:nil delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
innerAlert.tag = 2;
[innerAlert show];
[innerAlert release];
if (buttonIndex == 0 && alertView.tag == 1)
{
[self MethodCall];
}
}
else if (buttonIndex == 1 && alertView.tag == 1)
{
[alertView dismissWithClickedButtonIndex:1 animated:TRUE];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With