如何在UIVIewController中添加多个UIAlertview?
问题描述:
喜在我的视图控制器有一个以上的按钮,这些按钮将通过靶向的另一种方法。所以我用下面的代码而是两个警报享有如何在UIVIewController中添加多个UIAlertview?
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
这种方法完全不来电。这是我使用的整个代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section==1)
{
if(indexPath.row==0)
{
GMMAboutUsViewController *aboutus= [self.storyboard instantiateViewControllerWithIdentifier:@"aboutus"];
[self.navigationController pushViewController:aboutus animated:YES];
}
else if (indexPath.row==1)
{
GMMTermsOfServiceViewController *termsofservice= [self.storyboard instantiateViewControllerWithIdentifier:@"termsofservice"];
[self.navigationController pushViewController:termsofservice animated:YES];
}
else if (indexPath.row==2)
{
GMMUserGuideViewController *userguide= [self.storyboard instantiateViewControllerWithIdentifier:@"userguide"];
[self.navigationController pushViewController:userguide animated:YES];
}
else
{
GMMCreditsandCopyrightsViewController *creditsandcopyrights= [self.storyboard instantiateViewControllerWithIdentifier:@"creditsandcopyrights"];
[self.navigationController pushViewController:creditsandcopyrights animated:YES];
}
}
else
{
if(indexPath.row==0)
{
alertDeregister=[[UIAlertView alloc]
initWithTitle:@"Deregister"
message:@"Are you sure you want to Deregister ? "
delegate:nil
cancelButtonTitle:@"NO"
otherButtonTitles:nil, nil];
alertDeregister.tag=kFirstAlertViewTag;
[alertDeregister addButtonWithTitle:@"YES"];
[alertDeregister show];
}
else
{
alertLogout=[[UIAlertView alloc]
initWithTitle:@"Logout"
message:@"Are you sure you want to logout ? "
delegate:nil
cancelButtonTitle:@"cancel"
otherButtonTitles:nil, nil];
alertLogout.tag=kSecondAlertViewTag;
[alertLogout addButtonWithTitle:@"Logout"];
[alertLogout show];
}
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if(alertView==alertDeregister)
{
if(buttonIndex==0)
{
[self deregister];
}
}
else if (alertView==alertLogout)
{
if(buttonIndex==0)
{
GMMLoginController *login = [self.storyboard instantiateViewControllerWithIdentifier:@"l"];
[self presentModalViewController:login animated:NO];
}
}
}
答
您应该将自己作为委托来传递。
像
alertLogout=[[UIAlertView alloc]
initWithTitle:@"Logout"
message:@"Are you sure you want to logout ? "
delegate:self
cancelButtonTitle:@"cancel"
otherButtonTitles:nil, nil];
答
你不应该添加到您的.h文件中,只是添加委托:创建警报视图应该允许被称为clickedButtonAtindex方法时的自我。请加
NSLog("clickedButtonAtIndex called");
您clickedButtonAtIndex方法来检查其是否作为问题呼叫可以在其他地方
+0
好多了。谢谢! – 2013-07-18 00:29:50
您设置alertView到零的代表。在你的'[[UIAlertView alloc] initWith ...]'用'delegate:self'替换'delegate:nil'。 – 2013-04-09 19:11:14
我添加了委托:自我但仍然不能工作 – Naveen 2013-04-09 19:15:10
您是否在.h文件中添加了协议? – 2013-04-09 19:19:05