【问题标题】:UIAlertController.addTextFieldWithConfigurationHandler shows warning "the behavior of the UICollectionViewFlowLayout is not defined"UIAlertController.addTextFieldWithConfigurationHandler 显示警告“未定义 UICollectionViewFlowLayout 的行为”
【发布时间】:2016-03-19 11:21:06
【问题描述】:

当我尝试使用 addTextFieldWithConfigurationHandler 显示带有 textfeild 的 alertController 时,我收到了警告:

2015-12-14 11:03:32.022 TestAlertWithTextField[8455:1172878] UICollectionViewFlowLayout 的行为未定义,因为: 2015-12-14 11:03:32.022 TestAlertWithTextField[8455:1172878] 项目高度必须小于 UICollectionView 的高度减去部分插入顶部和底部值,减去内容插入顶部和底部值。 2015-12-14 11:03:32.023 TestAlertWithTextField[8455:1172878] 相关的 UICollectionViewFlowLayout 实例是 , 并附加到 ;层 = ;内容偏移:{0, 0}; contentSize: {0, 0}> 集合视图布局: . 2015-12-14 11:03:32.023 TestAlertWithTextField[8455:1172878] 在 UICollectionViewFlowLayoutBreakForInvalidSizes 处创建一个符号断点以在调试器中捕获此问题。

我不知道为什么。

代码:

@IBAction func onButtonClick(sender: UIButton) {
    let title = ""
    let style = UIAlertControllerStyle.Alert

    let alert = UIAlertController(title: title, message: "hello", preferredStyle: style)

    alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
        textField.placeholder = "pass"
    })

    let cancelTitle = "cancel"
    let cancelStyle = UIAlertActionStyle.Cancel
    let cancelHandler:((UIAlertAction) -> Void)? = { (action) -> Void in
        print("cancelHandler")
    }
    let cancelAction = UIAlertAction(title: cancelTitle, style: cancelStyle, handler: cancelHandler)

    alert.addAction(cancelAction)

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

【问题讨论】:

  • 您是否在应用程序的其他地方使用了 UICollectionView?此错误似乎不适用于您粘贴的代码。相反,您的 UICollectionView 单元格大小似乎大于屏幕大小。
  • @Patrick Tescher 不,我没有使用 UICollectionView,只是一个在 uiviewcontroller 上有一个按钮的简单应用程序

标签: swift uialertcontroller


【解决方案1】:

你需要打电话

alert.view.setNeedsLayout()

就在之前

self.presentViewController(alert, animated: true, completion: nil)

【讨论】:

    猜你喜欢
    • 2015-12-16
    • 2022-06-18
    • 2016-01-30
    • 2011-01-19
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 2016-01-14
    相关资源
    最近更新 更多