【问题标题】:XCODE iphone 6 plus and 6s plus shows warning when display UIAlertViewControllerXCODE iphone 6 plus 和 6s plus 在显示 UIAlertViewController 时显示警告
【发布时间】:2015-10-20 15:44:14
【问题描述】:

我是 iOS 开发的新手。我试图在单击按钮时显示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、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:>,它 附在 ;层 = ;内容偏移:{0, 0}; contentSize: {0, 0}> 集合视图布局: <_uialertcontrollercollectionviewflowlayout:>.

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

【问题讨论】:

  • 这可能很愚蠢,但请尝试在两个操作之前添加文本字段。
  • @rmaddy 它仍然显示警告。无论如何,我只是尝试添加 2 个文本字段,但它并未在所有平台上显示警告,我在添加 2 个操作的语句之前和之后添加了它(DefaultCancel
  • 向 Apple 提交错误。包括一个演示问题的简单测试应用程序。
  • 我找到了this线程。有人通过手动将 contentInset 设置为 UIEdgeInsetsZero 进行了修复,但看起来那里也提交了一份错误报告。
  • 我遇到过这个,但是你找不到集合视图来设置 UIEdgeInsetsZero

标签: ios iphone swift uialertcontroller


【解决方案1】:

尝试:

yourAlertController.view.setNeedsLayout()

就在用presentViewController:展示它之前

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

【讨论】:

  • 这消除了警告 - 我们应该仍然将错误提交给苹果,因为不需要这一行。
  • 在哪里查看 Apple 报告的错误状态?
【解决方案2】:

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

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

而不是

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-07
    • 1970-01-01
    相关资源
    最近更新 更多