我是iOS开发的新手。我尝试在按钮被点击时(故事板为空,只有1个按钮),使用以下代码显示一个UIAlertController
:
@IBAction func showAlert(sender: UIBarButtonItem) {
let alert = UIAlertController(
title: "Create new",
message: "Hi",
preferredStyle: UIAlertControllerStyle.Alert
)
let createAction = UIAlertAction(title: "Ok", style: .Default, handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alert.addAction(createAction)
alert.addAction(cancelAction)
alert.addTextFieldWithConfigurationHandler {
$0.placeholder = "Test placeholder"
}
presentViewController(alert, animated: true, completion: nil)
}
iPhone 5, 5s, 6, and 6s do not display warnings, but iPhone 6 Plus and 6s Plus do display warnings.
The behavior of the UICollectionViewFlowLayout is undefined because: 2015-10-20 22:38:54.007 TestApp[3128:48601] 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-10-20 22:38:54.008 TestApp[3128:48601] The relevant UICollectionViewFlowLayout instance is <_UIAlertControllerCollectionViewFlowLayout: 0x7fd6b8582d90>, and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x7fd6b8582d90>.
If I remove the text field on UIAlertController
or remove the two buttons (while keeping the text field displayed), no warning is displayed. Can you explain why this happens and how to fix it?
Default
和Cancel
)的语句之前和之后都添加了它们。 - sendy halim