【发布时间】:2015-10-20 15:44:14
【问题描述】:
我是 iOS 开发的新手。我试图在单击按钮时显示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、6s 不显示警告,但 iphone 6plus 和 6s plus 显示警告
2015-10-20 22:38:54.007 TestApp[3128:48601] 的行为 UICollectionViewFlowLayout 未定义,因为: 2015-10-20 22:38:54.008 TestApp[3128:48601] 项目高度必须小于 UICollectionView 的高度减去插入顶部和底部的部分 值,减去内容插入顶部和底部值。 2015-10-20 22:38:54.008 TestApp[3128:48601] 相关 UICollectionViewFlowLayout 实例是 <_uialertcontrollercollectionviewflowlayout:>,它 附在 ;层 = ;内容偏移:{0, 0}; contentSize: {0, 0}> 集合视图布局: <_uialertcontrollercollectionviewflowlayout:>.
如果我删除 UIAlertController 上的文本字段或删除 2 个按钮(保持文本字段显示),它不会显示警告。任何解释为什么会发生这种情况?如何修复警告?
【问题讨论】:
-
这可能很愚蠢,但请尝试在两个操作之前添加文本字段。
-
@rmaddy 它仍然显示警告。无论如何,我只是尝试添加 2 个文本字段,但它并未在所有平台上显示警告,我在添加 2 个操作的语句之前和之后添加了它(
Default和Cancel) -
向 Apple 提交错误。包括一个演示问题的简单测试应用程序。
-
我找到了this线程。有人通过手动将 contentInset 设置为 UIEdgeInsetsZero 进行了修复,但看起来那里也提交了一份错误报告。
-
我遇到过这个,但是你找不到集合视图来设置 UIEdgeInsetsZero
标签: ios iphone swift uialertcontroller