我正在尝试找出我需要使用的代码行,以确定是否在UIActionSheet中按下了“破坏性”按钮。
我环顾四周,找到了委托方法......
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
..我也找到了[myActionSheet destructiveButtonIndex]
,我只是不确定如何将两者放在一起。这是我到目前为止所尝试的并没有成功:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == destructiveButtonIndex)
{
// Do something...
}
}
答案 0 :(得分:11)
你的代码非常接近。您正在寻找的实施是:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.destructiveButtonIndex)
{
// Do something...
}
}
答案 1 :(得分:-2)
你必须检查如下
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Do something...
}
else if (buttonIndex == 1)
{
}
}