如何检查是否按下了"破坏性"按钮(UIActionSheet - iPhone)?

The*_*imp 3 iphone delegates uiactionsheet

我正在尝试找出我需要使用的代码行,以确定是否在UIActionSheet中按下了"破坏性"按钮.

我环顾四周,找到了委托方法......

 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Run Code Online (Sandbox Code Playgroud)

..而且我也设法找到了[myActionSheet destructiveButtonIndex],我只是不确定如何把两者放在一起.这是我迄今为止尝试过的但没有成功:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == destructiveButtonIndex) 
    {
        // Do something...
    }
}
Run Code Online (Sandbox Code Playgroud)

Ash*_*lls 11

你的代码非常接近.您正在寻找的实施是:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.destructiveButtonIndex) 
    {
        // Do something...
    }
}
Run Code Online (Sandbox Code Playgroud)