XCODE 在显示 UIAlertViewController 时,iPhone 6 Plus 和 6s Plus 显示警告。

8

我是iOS开发的新手。我尝试在按钮被点击时(故事板为空,只有1个按钮),使用以下代码显示一个UIAlertController

@IBAction func showAlert(sender: UIBarButtonItem) {
  let alert = UIAlertController(
    title: "Create new",
    message: "Hi",
    preferredStyle: UIAlertControllerStyle.Alert
  )

  let createAction = UIAlertAction(title: "Ok", style: .Default, handler: nil)
  let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)

  alert.addAction(createAction)
  alert.addAction(cancelAction)
  alert.addTextFieldWithConfigurationHandler {
    $0.placeholder = "Test placeholder"
  }

  presentViewController(alert, animated: true, completion: nil)
}

iPhone 5, 5s, 6, and 6s do not display warnings, but iPhone 6 Plus and 6s Plus do display warnings.

The behavior of the UICollectionViewFlowLayout is undefined because: 2015-10-20 22:38:54.007 TestApp[3128:48601] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values. 2015-10-20 22:38:54.008 TestApp[3128:48601] The relevant UICollectionViewFlowLayout instance is <_UIAlertControllerCollectionViewFlowLayout: 0x7fd6b8582d90>, and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x7fd6b8582d90>.

If I remove the text field on UIAlertController or remove the two buttons (while keeping the text field displayed), no warning is displayed. Can you explain why this happens and how to fix it?


1
@rmaddy,它仍然显示警告。无论如何,我刚刚尝试添加了2个文本字段,并且在所有平台上都没有显示警告,我在添加2个操作(DefaultCancel)的语句之前和之后都添加了它们。 - sendy halim
2
向苹果提交一个 bug。请包含一个简单的测试应用程序,以演示该问题。 - rmaddy
@rmaddy,我很好奇,如果你有时间运行上面的代码,这种情况也会发生在你身上吗? - sendy halim
1
就此而言,我找到了这个帖子。有一个人通过手动将contentInset设置为UIEdgeInsetsZero来解决了问题,但似乎也有一个错误报告被提交了。 - Aaron
1
我遇到了这个问题,但是你找不到集合视图来设置UIEdgeInsetsZero。 - Wingzero
显示剩余2条评论
2个回答

18

尝试:

yourAlertController.view.setNeedsLayout()

在使用presentViewController:方法展示之前。

编辑:我已向苹果提交了此错误。


1
这样可以消除警告 - 我们仍然应该向苹果提交错误报告,因为这行代码不应该需要。 - Sidetalker
在哪里可以查看苹果报告的漏洞状态? - triiiiista

0

我在我的屏幕上也遇到了同样的问题,只有iPhone 6 Plus屏幕。请检查一下,如果您没有传递空标题,请将标题设置为nil,如下所示:

UIAlertController *confirmAlert = [UIAlertController alertControllerWithTitle:nil message:displayMessage preferredStyle:UIAlertControllerStyleAlert];

替代

  UIAlertController *confirmAlert = [UIAlertController alertControllerWithTitle:@"" message:displayMessage preferredStyle:UIAlertControllerStyleAlert];

它解决了我的问题。祝你好运。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接