【问题标题】:Pressing Cancel button doesn't retract按取消按钮不会缩回
【发布时间】:2010-08-23 07:59:29
【问题描述】:

我正在实施一个行动表。当我按“确定”按钮时,执行这些操作,按“取消”返回。 “确定”按钮工作正常,但是当我按下“取消”按钮时,什么也没有发生,它不会缩回或做任何事情,只是挂在操作表视图上。

下面是我的代码:

在导航栏上创建按钮:

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中。

【问题讨论】:

    标签: iphone objective-c cocoa-touch ios


    【解决方案1】:

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

    似乎是标签栏的问题。如果调用 UIActionSheet 的

    [sheet showInView:self.view]
    

    从作为 UITabViewController 子级的视图控制器,然后 取消按钮的命中测试在该部分失败 位于标签栏视图上方的 UIActionSheet。

    如果您改为传入 UITabBarController 的视图,则 UIActionSheet 会按预期运行。

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

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

    【讨论】:

      【解决方案2】:

      我不知道它是否能解决这个问题,但你会想做buttonIndex != [actionSheet cancelButtonIndex](检查不等于)而不是!buttonIndex == [actionSheet cancelButtonIndex](反转buttonIndex(!)并检查是否相等) .

      【讨论】:

        【解决方案3】:

        您需要使用 showFromBarButtonItem 而不是 showInView。问题是取消按钮被另一个视图覆盖——可能是工具栏或标签栏——所以它没有得到你认为它应该得到的触摸事件。还有有时应该使用的 showFromTabBar 和 showFromToolbar(参见 UIActionSheet 类参考)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-11-09
          • 2013-08-10
          • 2018-08-29
          • 1970-01-01
          • 2013-10-05
          • 1970-01-01
          • 2019-06-23
          • 2021-04-12
          相关资源
          最近更新 更多