作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试使用 addTextFieldWithConfigurationHandler 呈现带有 textfeild 的警报 Controller 时,我收到警告:
2015-12-14 11:03:32.022 TestAlertWithTextField[8455:1172878] the behavior of the UICollectionViewFlowLayout is not defined because:2015-12-14 11:03:32.022 TestAlertWithTextField[8455:1172878] 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-12-14 11:03:32.023 TestAlertWithTextField[8455:1172878] The relevant UICollectionViewFlowLayout instance is , and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: .2015-12-14 11:03:32.023 TestAlertWithTextField[8455:1172878] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
I do not know why.
The code:
@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)
}
最佳答案
您需要调用
alert.view.setNeedsLayout()
就在之前
self.presentViewController(alert, animated: true, completion: nil)
关于swift - UIAlertController.addTextFieldWithConfigurationHandler 显示警告 "the behavior of the UICollectionViewFlowLayout is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34259227/
在 WKWebView 的 JavaScript 中调用 window.prompt 会产生断言错误: Assertion failure in -[UIAlertController addText
我正在制作一个包含几个文本字段的警报,一旦点击保存,它就会保存在服务器上。我设法让它发挥作用,但发现了一些我不明白的奇怪之处。我不确定如何用文字解释它,所以我会发布有问题的代码。 var entere
当我尝试使用 addTextFieldWithConfigurationHandler 呈现带有 textfeild 的警报 Controller 时,我收到警告: 2015-12-14 11:03:
我是一名优秀的程序员,十分优秀!