如何检查'破坏性'按钮是否被按下(UIActionSheet-iPhone)?
问题描述:
我试图弄清楚我需要使用的代码行,以确定'破坏性'按钮是否在UIActionSheet中按下。如何检查'破坏性'按钮是否被按下(UIActionSheet-iPhone)?
我周围一看,发现委托方法...
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
..而我也设法找到[myActionSheet destructiveButtonIndex]
,我只是不知道如何把这两者结合起来。这是我一直没有成功到目前为止已经试过:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == destructiveButtonIndex)
{
// Do something...
}
}
答
你是非常接近的与您的代码。你正在寻找的实现是:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.destructiveButtonIndex)
{
// Do something...
}
}
答
你必须检查像下面
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Do something...
}
else if (buttonIndex == 1)
{
}
}
+3
错误。 OP正在寻找具有破坏性的按钮。 UIActionSheet上有一个属性可以找到它。 –
谢谢 - 这就是我一直在寻找的东西。我知道我很接近;) –
非常感谢!不知道这个getters。非常棒 – aumanets