ios - UIActionSheet 在第二次单击按钮时关闭

标签 ios cocoa-touch uiactionsheet

我有一个带有 EDIT 和 DELETE 按钮的 actionSheet,它们都是其他按钮 这是我为它编写的代码

-(void)method1
{

    action = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil     destructiveButtonTitle:nil otherButtonTitles:@"Edit", @"Delete", nil];
     action.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [action showInView:self.view];
    [action release]; 

}

我已经使用 deleate 方法将操作分配给方法..

-(void)actionSheet:(UIActionSheet *)action didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0)
    {
        // do something
    }
    if(buttonIndex == 1)
    {
        // do something
    }
}

现在的问题是单击任一按钮后操作表不会消失。请帮我解决一些问题。

最佳答案

这似乎是 iOS4.0 中的一个错误。我在我的模拟器中遇到了这个问题。我将版本更改为 4.3 和 5.0,似乎还可以。

编辑:

似乎我的问题更具体地与通过委托(delegate)方法“-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField”启动两次的操作表有关

不确定为什么在这种情况下会调用两次而不是其他情况(我再次假设 iOS 4.0 错误已在以后的版本中修复)。我的解决方法是跟踪它是否已被调用并且不再调用它。

编辑2

我建议做这样的事情:

-(void)method1
{
    if(hasLaunchedActionSheet)
    {
        return;
    }

    hasLaunchedActionSheet = YES;
    ...

和:

-(void)actionSheet:(UIActionSheet *)action didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    hasLaunchedActionSheet = NO;
    ...

对我来说,问题不在于 Xcode,而在于 iOS SDK 本身两次调用我的事件。我不确定你是如何调用 method1 的,所以它可能是不同事件的不同问题。

关于ios - UIActionSheet 在第二次单击按钮时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8678402/

相关文章:

iphone - 以编程方式设置 UITabBar 标题

cocoa-touch - 发布通知时出现 NSInvalidArgumentException

ios - 缩放字体大小以垂直适合 UILabel

iphone - 如何在 UIDatePicker iphone 中只显示时间

ios - 如何删除 LineChartView iOS 图表中的点

ios - 如何在 IOS 运行时切换到语言后获取本地化的 Storyboard字符串?

iphone - 圆角 UIView 或 UIImageView

ios - 带有 UIDatePicker subview 的 UIActionSheet 有一个小的透视区域

ios - ActionSheet 未正确显示

ios - 将 Google Cast SDK 添加到 64 位版本