【问题标题】:UIActionSheet from UIAlertView来自 UIAlertView 的 UIActionSheet
【发布时间】:2011-11-29 08:19:39
【问题描述】:

我试图在用户触摸 UIAlertView 中的按钮时显示 UIActionSheet:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    if (buttonIndex == 0)
    {
        UIActionSheet *actionSheet = ...
        [actionSheet showFromTabBar:self.tabBarController.tabBar];
    }
}

当显示操作表时,警报视图仍在操作表后面的屏幕上,当我触摸操作表中的按钮时 - 操作表消失但整个屏幕变暗,警报视图仍然打开并且我无法关闭它。

我尝试了几件事,例如在短暂延迟后显示操作表或以编程方式关闭警报视图,但没有任何效果。在最好的情况下(以编程方式关闭警报视图),警报视图确实在一个有点奇怪的转换后消失了,但是当它出现时,我在日志中收到“等待栅栏无法接收回复”错误。

如何从警报视图中有序地显示操作表?

【问题讨论】:

    标签: iphone ios xcode uialertview uiactionsheet


    【解决方案1】:

    在这种情况下,你应该使用

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    

    方法而不是,

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

    所以你的代码将是:

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0)
        {
            UIActionSheet *actionSheet = ...
            [actionSheet showFromTabBar:self.tabBarController.tabBar];
        }
    }
    

    谢谢,

    【讨论】:

      【解决方案2】:

      只需为 UIAlertView 调用 dismissWithClickedButtonIndex:animated: 方法

      if (buttonIndex == 0)
      {
          [alertView dismissWithClickedButtonIndex:0 animated:YES];
          UIActionSheet *actionSheet = ...
          [actionSheet showFromTabBar:self.tabBarController.tabBar];
      }
      

      【讨论】:

      • 当我调用此方法时,警报视图会被删除,但过渡有点奇怪,但我在日志中收到“等待栅栏无法接收回复”错误。我正在寻找一个干净的解决方案。
      • 什么是“有点奇怪的过渡”?我已经实现了这个功能,没有任何警告。一切正常。
      • 表示过渡不顺畅。好像警报视图开始消失并立即再次出现然后消失。正如我所说,我还收到一条错误消息,说“wait-fence failed to receive reply”,这并不完全是“工作正常”(即使用户没有看到错误消息,我也不愿意接受)。我确实说过我已经尝试过这个解决方案,这是不可接受的。正确答案是拉文给出的答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多