UIAlertActions не отображается при тестировании на физическом устройстве - PullRequest
0 голосов
/ 10 декабря 2018

В моем приложении я создаю QR-код, который затем представляю пользователю в качестве предупреждения с помощью UIAlertController.Я добавляю изображение QR-кода в качестве подпредставления к предупреждению.Я также добавляю две операции UIAlertActions: одна сохраняет 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)
...