Sorting out 2 UIalertview's button clicks
I have 2 alerts on the same page. Problem is that the clickedButtonAtIndex is answering both alerts and not just the second one. How do I separate them?
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Phone Number" message:@"\n\n\n"
delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct phone no." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
On the first one you enter a phone number and hit ok. If it validates, great. However if it does not the second alert shows. Now when they hit开发者_JAVA百科 "Try Again" the clickedButtonAtIndex runs on the first and second alert. I need it to only run on the second.
What you have to do is give different tag to both alert view and then access by tags as:-
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Phone Number" message:@"\n\n\n"
delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];
passwordAlert.tag=1;
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct phone no." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];
alert.tag=2;
- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(alert.tag==1)
{
if (buttonIndex==0) {
}
else if (buttonIndex==1) {
}
}
if(alert.tag==2)
{
if (buttonIndex==0) {
}
else if (buttonIndex==1) {
}
}
精彩评论