XCODE iphone 6加6s加显示UIAlertViewController时显示警告

XCODE iphone 6 plus and 6s plus shows warning when display UIAlertViewController

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

@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 {
    [=12=].placeholder = "Test placeholder"
  }

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

iphone 5, 5s, 6, 6s 不显示警告,但是 iphone 6plus 和 6s plus 显示警告

2015-10-20 22:38:54.007 TestApp[3128:48601] the behavior of the UICollectionViewFlowLayout is not defined because: 2015-10-20 22:38:54.008 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>.

如果我删除 UIAlertController 上的文本字段或删除 2 个按钮(保持文本字段显示),它不会显示警告。任何解释为什么会这样?如何修复警告?

尝试:

yourAlertController.view.setNeedsLayout()

就在用 presentViewController:

呈现之前

编辑:我已将此错误提交给 Apple

我的屏幕也有同样的问题,只有 iphon6 plus 屏幕。请检查,如果您没有传递空标题,如果标题为空,则将其传递为 nil,例如:

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

而不是

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

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