Ios 我的代码试图对弹出按钮做出反应有什么问题
我试图在用户单击带有警告的按钮时显示一个弹出窗口,如果他们单击“取消”,它将被取消,但如果他们单击“继续”,我希望它显示视图控制器。这是我的代码,但无论我按哪个按钮,它都只会关闭弹出窗口:Ios 我的代码试图对弹出按钮做出反应有什么问题,ios,uialertview,Ios,Uialertview,我试图在用户单击带有警告的按钮时显示一个弹出窗口,如果他们单击“取消”,它将被取消,但如果他们单击“继续”,我希望它显示视图控制器。这是我的代码,但无论我按哪个按钮,它都只会关闭弹出窗口: - (IBAction)latest:(id)sender { alert = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Continuing will use internet and may cause app to slow
- (IBAction)latest:(id)sender {
alert = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Continuing will use internet and may cause app to slow down in large crowds" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 2) {
UIViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Latest"];
[self presentViewController:NVC animated:YES completion:Nil];
}
}
您只有两个选项可以单击。索引从0而不是1开始,因此将
if(buttonIndex==2)
更改为if(buttonIndex==1)
您的问题很简单-您需要将self
作为警报视图的委托传递,而不是nil
另外,在委托方法中,不要硬编码按钮索引。改为这样做:
if (buttonIndex == alertView.firstOtherButtonIndex) {
}
好吧,我知道了。我必须将代理设置为self,它被设置为“nil”。我将其同时更改为1和0,但两者都不起作用。我将在5分钟内进行一点游戏,然后返回NSLog(“调用”);如果函数被调用,则返回se。