Objective c 目标C:AlertView不起作用

Objective c 目标C:AlertView不起作用,objective-c,uialertview,uiactionsheet,Objective C,Uialertview,Uiactionsheet,在用户单击操作表中的“destructButton”后,我实现了一个警报视图。代码片段如下所示: -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex != actionSheet.cancelButtonIndex) { UIAlertView *alert = [[UIAlertView alloc]

在用户单击操作表中的“destructButton”后,我实现了一个警报视图。代码片段如下所示:

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
  if (buttonIndex != actionSheet.cancelButtonIndex)
  {
     UIAlertView *alert = [[UIAlertView alloc] 
     initWithTitle:@"Something happened!"
     message:nil
     delegate:nil
     cancelButtonTitle:@"Phew!"
     otherButtonTitles:nil];
  }

  [alert show];
  [alert release];
}
我已经将UIActionSheetDelegate协议包含在我的.h文件中

@interface Control_FunViewController : UIViewController <UIActionSheetDelegate> {
    UITextField *nameField;
    UITextField *numberField;
    UILabel *sliderLabel;
    UISwitch *leftSwitch;
    UISwitch *rightSwitch;
    UIButton *doSomethingButton;

}
@接口控制\u FunViewController:UIViewController{
UITextField*nameField;
UITextField*数字字段;
UILabel*滑动标签;
UISwitch*左开关;
UISwitch*右开关;
UIButton*doSomethingButton;
}
但当我点击操作表中的destructButton时,什么也没发生。我是不是遗漏了什么

谢谢


Zhen

您的学员需要实施
操作表:点击按钮索引:

操作表:单击按钮索引:
后,操作表将被取消,然后代表将收到
操作表:didDismissWithButtonIndex:

。。。代理必须实现 操作表:单击按钮索引: 当按下这些按钮时要响应的消息 点击;否则,你的习惯 按钮不起作用。行动单 将在 操作表:点击按钮索引: 调用委托方法

您可以查看使用UIActionSheet的示例项目,如:


您已将UIActionSheetDelegate添加到.h文件中。这还不够。还必须为UIActionSheet对象设置委托。请参阅下面的编码:

-(作废)展示单 { UIActionSheet*操作=[[UIActionSheet alloc]initWithTitle:@“dsfs”委托:自取消按钮:@“第一个Btn”破坏性按钮:@“目的地Btn”其他按钮:无]; [动作秀查看:self.view]

}


在这段代码中,我将UIActionSheet的委托设置为self,如果您在ViewController(Control\u FunViewController)上添加了此方法,则此方法有效

我认为你的代码甚至不能编译。为什么显示的
警报不在定义范围内?
    // Action sheet delegate method.
    -      (void)actionSheet:(UIActionSheet *)actionSheet
        clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        // the user clicked one of the OK/Cancel buttons
        if (buttonIndex == 0)
        {
            [passwordItem resetKeychainItem];
            [accountNumberItem resetKeychainItem];
            [self.tableView reloadData];
        }
    }