Home>
No alert is displayed when opening the app. Please tell me the cause. Please.
override func viewDidLoad () {
super.viewDidLoad ()
alert ()
}
func alert () {
let alert: UIAlertController = UIAlertController (title: "Who are you?", message: "Please select", preferredStyle: UIAlertController.Style.alert)
let appleButton: UIAlertAction = UIAlertAction (title: "apple", style: UIAlertAction.Style.default, handler: {
(action: UIAlertAction!)->Void in
print ("OK")
})
let orangeButton: UIAlertAction = UIAlertAction (title: "Orange", style: UIAlertAction.Style.default, handler: {
(action: UIAlertAction!)->Void in
print ("Cancel")
})
// Button added
alert.addAction (appleButton)
alert.addAction (orangeButton)
// Display Alert
present (alert, animated: true, completion: nil)
}
-
Answer # 1
Related articles
- [swift 5, ios-charts] how to add a new line to the already displayed line chart view
- swift - index out of range is displayed
- xcode - swift undefined symbol is displayed
- value is not displayed in text in swift
- swift - mapview cannot be displayed
- [swiftui] two back buttons of navigation view are displayed
- swift - delete of tableviewcell is not displayed well
- xcode - swift: cell not displayed in tableview
- ios - [swift] alert not displayed
- ios - in swift, the image in the cell of tableview is displayed or hidden by if branch, but it does not work
- swift - flurryad is not displayed
- ios - [swift] video player play if displayed, stop if hidden
Trends
Because it is not displayed on the screen at the timing of viewDidLoad,
It's a good idea to write it only once around viewDidAppear.