当AlertController呈现

时间:2016-02-25 07:07:31

标签: ios objective-c swift

我想在超级ViewController中呈现一个AlertController。 (事实上​​,它没有CollectionView),但是当AlertController出现时。调试区域会调用一些错误:

//2016-02-25 14:55:06.721 treatα[53173:1063624] the behavior of the 
UICollectionViewFlowLayout is not defined because:
//2016-02-25 14:55:06.721 treatα[53173:1063624] 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.
//2016-02-25 14:55:06.722 treatα[53173:1063624] The relevant UICollectionViewFlowLayout instance is
 <_UIAlertControllerCollectionViewFlowLayout: 0x7fc883dfb1d0>, and it is attached to <UICollectionView: 0x7fc8848de800; 
frame = (0 104.667; 270 44); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7fc883dfbb50>; layer = <CALayer: 0x7fc883dfb680>; contentOffset: {0, 0}; 
contentSize: {0, 0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x7fc883dfb1d0>.
//2016-02-25 14:55:06.722 treatα[53173:1063624] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes
             to catch this in the debugger.

2 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。需要添加

alert.view.setNeedsLayout()

self.presentViewController(alert, animated: true, completion: nil)

然后,修复bug

答案 1 :(得分:0)

我的屏幕上也只有iphon6 plus屏幕也有同样的问题。请检查,如果你没有传递空标题,如果标题是空的,则传递给它,如:

 UIAlertController *confirmAlert = [UIAlertController alertControllerWithTitle:nil message:displayMessage preferredStyle:UIAlertControllerStyleAlert];

而不是

 UIAlertController *confirmAlert = [UIAlertController alertControllerWithTitle:@"" message:displayMessage preferredStyle:UIAlertControllerStyleAlert];

它解决了我的问题。祝你好运..