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,completion: nil)
资料来源:https://forums.developer.apple.com/thread/18294(最后回答)