显示UIAlertViewController时,XCODE iphone 6 plus和6s plus会显示警告

时间:2015-10-20 15:44:14

标签: ios iphone swift uialertcontroller

我是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 {
    $0.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]的行为   未定义UICollectionViewFlowLayout,因为:   2015-10-20 22:38:54.008 TestApp [3128:48601]项目高度必须小于   UICollectionView的高度减去顶部和底部的插入部分   值减去内容的顶部和底部值。 2015年10月20日   22:38:54.008 TestApp [3128:48601]相关   UICollectionViewFlowLayout实例是   < _UIAlertControllerCollectionViewFlowLayout:0x7fd6b8582d90>,然后它   附在; layer =; contentOffset:{0,   0}; contentSize:{0,0}>集合视图布局:   < _UIAlertControllerCollectionViewFlowLayout:0x7fd6b8582d90>。

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

2 个答案:

答案 0 :(得分:18)

尝试:

yourAlertController.view.setNeedsLayout()

在使用presentViewController:

呈现之前

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

答案 1 :(得分:0)

我的屏幕上也只有iphon6 plus屏幕也有同样的问题。请检查,如果你没有传递空标题,如果标题是空的,则传递给它,如:

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

而不是

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

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