简体   繁体   English

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

[英]XCODE iphone 6 plus and 6s plus shows warning when display UIAlertViewController

I'm a newbie in iOS development. 我是iOS开发的新手。 I was trying to display a UIAlertController when a button is clicked (The storyboard is empty, there's only 1 button in the storyboard), using below code 单击按钮时我试图显示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 do not show warnings, however iphone 6plus and 6s plus shows warning 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.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] The relevant UICollectionViewFlowLayout instance is <_UIAlertControllerCollectionViewFlowLayout: 0x7fd6b8582d90>, and it is attached to ; 2015-10-20 22:38:54.008 TestApp [3128:48601]相关的UICollectionViewFlowLayout实例是<_UIAlertControllerCollectionViewFlowLayout:0x7fd6b8582d90>,它附加到; layer = ; layer =; contentOffset: {0, 0}; contentOffset:{0,0}; contentSize: {0, 0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x7fd6b8582d90>. contentSize:{0,0}>集合视图布局:<_ UIAlertControllerCollectionViewFlowLayout:0x7fd6b8582d90>。

If I remove the text field on UIAlertController or I remove the 2 buttons (keep the text field displayed), it does not show warnings. 如果我删除UIAlertController上的文本字段或删除2个按钮(保持显示文本字段),它不会显示警告。 Any explanation why this happens? 任何解释为什么会这样? How to fix the warning? 如何修复警告?

try: 尝试:

yourAlertController.view.setNeedsLayout()

just before presenting it with presentViewController: 在使用presentViewController:呈现它之前presentViewController:

edit: I have submitted this bug to Apple 编辑:我已将此错误提交给Apple

I also had same issue in my screen for only iphon6 plus screen. 我的屏幕上也只有iphon6 plus屏幕也有同样的问题。 Please check, if you are not passing empty title, if title is empty , pass it nil like : 请检查,如果你没有传递空标题,如果标题是空的,则传递给它如下:

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

instead of 代替

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

it fixed my problem. 它解决了我的问题。 Good luck.. 祝好运..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM