Ios UIAlertView按钮操作
我如何使用两个操作来点击Ios UIAlertView按钮操作,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我如何使用两个操作来点击UIButtonclick?我有一个带有两个按钮的UIAlertView。再次播放并退出。现在我想在这些按钮的点击事件中执行两个方法。更新-2016年5月 UIAlertView已弃用。如前所述,现在可以使用UIAlertController 带UIAlertView的旧答案 您可以像这样创建UIAlertView UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really reset?"
UIButton
click?我有一个带有两个按钮的UIAlertView。再次播放并退出。现在我想在这些按钮的点击事件中执行两个方法。更新-2016年5月
UIAlertView已弃用。如前所述,现在可以使用UIAlertController
带UIAlertView的旧答案
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really reset?"
message:@"Do you really want to reset this game?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"reset", nil];
[alert show];
UIAlertViewDelegate
协议
@interface YourViewController:UIViewController<UIAlertViewDelegate>{
.......
.......
}
请创建更多的上下文,您的问题包含UIAlertView一词,描述中没有提示这一点。我已更新了问题。请现在检查。并告诉我如何才能做到这一点?我无法解决问题。是的……您能帮我吗?我应该将此函数放在哪里:-(无效)alertView:(UIAlertView*)alertView ClickedButtonIndex:(NSInteger)buttonIndex{if(buttonIndex==0){//cancel clicked…do your action}否则如果(buttonIndex==1){//reset clicked}请确保符合UIAlertViewDelegate协议。Ops yes..也做一件事,在控制器的.h文件中,确认UIAlertViewProtocol,即当我们声明@interface SomeController:UIViewControllermy.h文件时,如果您的控制器名称是.h文件中的SomeController,开始时已是这样:我如何在此处使用另一个委托?@interface GameTableView:UITableViewController[alertView cancelButtonIndex]
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == [alertView cancelButtonIndex]){
//cancel clicked ...do your action
}else{
//reset clicked
}
}