sendy halim sendy halim - 5 months ago 24
Swift Question

XCODE iphone 6 plus and 6s plus shows warning when display UIAlertViewController

I'm a newbie in iOS development. I was trying to display a

UIAlertController
when a button is clicked (The storyboard is empty, there's only 1 button in the storyboard), using below code

@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, 6s do not show warnings, however iphone 6plus and 6s plus shows warning


2015-10-20 22:38:54.007 TestApp[3128:48601] the behavior of the
UICollectionViewFlowLayout is not defined because:
2015-10-20 22:38:54.008 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 I remove the 2 buttons (keep the text field displayed), it does not show warnings. Any explanation why this happens? How to fix the warning?

Answer

try:

yourAlertController.view.setNeedsLayout()

just before presenting it with presentViewController:

edit: I have submitted this bug to Apple

Comments