我正在使用 UIAlertController 获取用户输入并更新表格单元格。每次当我尝试创建警报时,我都会在控制台中收到以下警告
2015-11-19 17:51:42.034 SimpleTableView[5488:584215] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-11-19 17:51:42.035 SimpleTableView[5488:584215] 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-11-19 17:51:42.036 SimpleTableView[5488:584215] The relevant UICollectionViewFlowLayout instance is <_UIAlertControllerCollectionViewFlowLayout: 0x7fd0a057c3d0>, and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x7fd0a057c3d0>. 2015-11-19 17:51:42.036 SimpleTableView[5488:584215] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
如许多博客中所述,实现非常简单,
func displayAlertInfo(){
let alertController = UIAlertController(title: "New Race", message: "Type in a new race", preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (_) in
alertController.dismissViewControllerAnimated(true, completion: nil)
}
let addAction = UIAlertAction(title: "Add", style: .Default) { (_) in
let textFieldInput = alertController.textFields![0] as UITextField
let newRace = textFieldInput.text?.capitalizedString
DataManager.sharedInstance.addRace(species: self.species, race: newRace!)
let newIndexPath = NSIndexPath(forRow: self.races.count - 1, inSection: 0)
self.racesTableVew.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "New Race"
}
alertController.addAction(cancelAction)
alertController.addAction(addAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
我在点击导航按钮时调用此函数。警报显示正确,但每次我尝试点击创建警报的按钮时,我都会收到此警告。 我做错了什么或者我跳过了什么?
编辑:添加屏幕截图:通过 tableView 从导航项按钮调用警报。
最佳答案
你需要打电话
alertcontroller.view.setNeedsLayout()
就在
self.presentViewController(alertController, animated: true, completion: nil)
来源:https://forums.developer.apple.com/thread/18294 (最后一个答案)
关于ios - UIAlertController : UICollectionViewFlowLayout is not defined warning every time I try to bringup a UIAlertcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33804091/