Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIAlertView按钮操作_Ios_Objective C_Cocoa Touch - Fatal编程技术网

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

    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];
    
  • 要处理AlertView按钮单击,您必须 遵守
    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
        }
    }