在物理设备上测试时未显示UIAlertActions

时间:2018-12-10 15:06:55

标签: ios swift uialertcontroller uialertaction

在我的应用程序中,我正在生成一个QR码,然后使用UIAlertController将其作为警报呈现给用户。我将QR码图像作为子视图添加到警报中。我还添加了两个UIAlertAction:一个将QR码保存到数据库中,另一个将其丢弃。

当我在模拟器中测试该应用程序时,所有程序都将在所有设备上完全按预期运行。但是,当我在物理设备(iPhone 5)上运行它时,两个UIAlertAction没有显示。

我似乎无法弄清楚这里出了什么问题。

这是我的代码:

qrImage = UIImage(ciImage: transformImage)

let alert = UIAlertController(title: "QR Code Created!", message: nil, preferredStyle: .alert)

let alertImageView = UIImageView(frame: CGRect(x: 10, y: 50, width: 250, height: 250))

alertImageView.image = qrImage

alert.view.addSubview(alertImageView)

let height = NSLayoutConstraint(item: alert.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 360)

let width = NSLayoutConstraint(item: alert.view, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 270)

alert.view.addConstraint(height)
alert.view.addConstraint(width)

let saveAction = UIAlertAction(title: "Save", style: .default) { (action) in 

//Code here to save image to database.

 }

let discardAction = UIAlertAction(title: "Discard", style: .destructive, handler: nil)

alert.addAction(saveAction)
alert.addAction(discardAction)


present(alert, animated: true, completion: nil)

0 个答案:

没有答案