iphone - 按取消按钮不会缩回

标签 iphone objective-c cocoa-touch ios

我正在实现一份行动表。当我按“确定”按钮时,执行这些操作,按“取消”返回。 “确定”按钮工作正常,但是当我按下“取消”按钮时,没有任何反应,它不会缩回或执行任何操作,只是卡在操作 TableView 上。

下面是我的代码:

在导航栏上创建按钮:

UIBarButtonItem *clearButton = [[[UIBarButtonItem alloc] initWithTitle:@"Clear     History"
                                                                      style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:@selector(ClearHistoryAction:)] autorelease];
self.navigationItem.leftBarButtonItem = clearButton;

当我单击并启动操作表时:

   - (IBAction)ClearHistoryAction:(id)sender
  {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:@"Clear History?"
                              delegate:self
                              cancelButtonTitle:@"Cancel"
                              destructiveButtonTitle:@"OK"
                              otherButtonTitles:nil];


// use the same style as the nav bar
actionSheet.actionSheetStyle = self.navigationController.navigationBar.barStyle;    

[actionSheet showInView:self.view];
    [actionSheet release];


    }

如果选择“确定”,请执行以下操作:

  - (void)actionSheet:(UIActionSheet *)actionSheet

 didDismissWithButtonIndex:(NSInteger) buttonIndex
  {
if (!buttonIndex == [actionSheet cancelButtonIndex])
{

    //do what i want here!
}
  }

在头文件中,UIActionSheetDelegate包含在@interface中。

最佳答案

迟到了,但可能的解释是:

Seems to be an issue with the tabbar. If you call UIActionSheet's

[sheet showInView:self.view]

from a view controller that is a child of a UITabViewController, then the hit testing on the cancel button fails in that portion of the UIActionSheet that lies above the tabbar's view.

如果您改为传入 UITabBarController 的 View ,则 UIActionSheet 将按预期运行。

[sheet showInView:self.parentViewController.tabBarController.view];

这里有更详细的解释: UIActionSheet cancel button strange behaviour

关于iphone - 按取消按钮不会缩回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3545657/

相关文章:

ios - Twitter SLComposeViewController 经常无法触发

ios - 滚动时背景 alpha 过渡

iphone - 如何显示一条 iPhone 消息(警报?),看起来就像切换静音模式时显示的消息一样

objective-c - 在主线程上执行带有多个参数的方法的最简单方法是什么?

ios - 如何使用百分比调用方法

iphone - iOS9 上的 UIAlertController ActionSheet 问题

iphone - 默认情况下,UITableView编辑模式

ios - NSFetchedResultsController 的复杂获取请求

ios - 获取 UITextView 的实际高度

iphone - 2 台 iOS 设备之间的蓝牙连接