gpt4 book ai didi

swift - UIAlertController.addTextFieldWithConfigurationHandler 显示警告 "the behavior of the UICollectionViewFlowLayout is not defined"

转载 作者:行者123 更新时间:2023-11-30 13:51:01 24 4
gpt4 key购买 nike

当我尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com