4

我有一个基于“基于窗口的应用程序”模板的 iPhone 应用程序,它使用带有一些嵌入式子视图的主视图。

对于某些操作,我需要用户确认。因此,我创建了一个 UIActionSheet 并要求用户提供反馈。

问题是,操作表根本没有显示。相反,屏幕变暗。工作表和请求的按钮不显示。之后,应用程序挂起。屏幕变暗是作为动画的一部分的正常行为,通常显示动作表。

奇怪的是,如果在 viewDidLoad 方法中调用相同的代码,也可以正常工作。如果在启动需要确认的操作的 buttonPressed 方法中调用,它不起作用。

- (void) trashButtonPressed {
   // This method is called in the button handler and (for testing
   // purposes) in the viewDidLoad method.
   NSLog( @"trashButtonPressed" );

   UIActionSheet* actionSheet =
        [[UIActionSheet alloc] initWithTitle: @"Test" 
                                    delegate: self 
                           cancelButtonTitle: @"Cancel"
                      destructiveButtonTitle: @"Delete Sheet"
                           otherButtonTitles: nil];

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

- (void)       willPresentActionSheet:(UIActionSheet *)  actionSheet {
   NSLog( @"willPresentActionSheet" );
}

- (void)       didPresentActionSheet:(UIActionSheet *)   actionSheet {
   NSLog( @"didPresentActionSheet" );
}

- (void)        actionSheet:(UIActionSheet *)actionSheet
  didDismissWithButtonIndex:(NSInteger)buttonIndex {
   NSLog( @"actionSheet:didDismissWithButtonIndex" );
}

如您所见,我已将一些日志消息添加到 UIActionSheetDelegateProtocol 的协议处理程序中。“将呈现”和“确实呈现”方法按预期调用,但工作表未显示。

有谁知道,这里有什么问题?

4

2 回答 2

3

我想知道是否[actionSheet showInView: self.view];足以让 actionSheet 本身由 self.view 保留。编辑:保留计数从 1 跳到 4,所以这里不是问题)

你检查过视图的尺寸吗?工作表位于视图内,但如果 self.view 引用一个大滚动视图,您可能只有在表面下方有一个工作表。简而言之,您确定 self.view.frame 和 self.view.bounds 在您所指的两种情况下具有相同的值吗?它是相同的视图吗(当只是NSLog(@"%x",self.view)-ing 它的地址时)?

编辑澄清:做

NSLog(@"%f %f %f %f",
        self.view.frame.origin.x,self.view.frame.origin.y,
        self.view.frame.size.width,self.view.frame.size.height);

并请说出您在控制台上看到的内容。如果我设置 0,0,0,0 帧或 0,0,320,800 帧,我会得到你的“屏幕变暗”,所以这可能是它......

于 2010-08-01T00:46:02.270 回答
0

实际上,我认为您遇到了与我看到的相同的问题。

在 iOS 8 和 9 中,UIActionSheet 确实会显示...哦...但是在屏幕键盘后面,所以您看不到它。您只会看到屏幕的其余部分变暗。

显然,这是 Apple 最新的 UI 改进想法,以保持屏幕整洁。;-)

简单的解决方案是在显示之前添加一行代码UIActionSheet

[self.view endEditing:true];

这会关闭屏幕键盘,让您美丽的操作表再次可见。

或者,我在这里记录了如何UIActionSheetUIAlertController.

于 2016-02-11T09:08:17.013 回答