ios – UIAlertController:UICollectionViewFlowLayout在每次尝试启动UIAlertcontroller时都不会被警告

前端之家收集整理的这篇文章主要介绍了ios – UIAlertController:UICollectionViewFlowLayout在每次尝试启动UIAlertcontroller时都不会被警告前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用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,completion: nil)

资料来源:https://forums.developer.apple.com/thread/18294(最后回答)

原文链接:https://www.f2er.com/iOS/329563.html

猜你在找的iOS相关文章