Sometimes we need a frame to confirm or return when we do the operation, which is alertview. In the previous project, when we clicked the Stop button, the pop-up window was confirmed. Pop-up window This action occurs when we click the Stop button, so the Alertview code is added to the Stop button action, the code is as follows:
@IBAction func Stopbutton (Sender:uibutton) {let stopdownloadconfirm = Uialertview (title: "Warning", message: "Downloading, Are you sure you want to cancel the download? ", Delegate:self, Cancelbuttontitle:" No ", Otherbuttontitles:" yes ") stopdownloadconfirm.show () }
Of course, because the agent chooses self, the controller needs to integrate the uialertviewdelegate, which works as follows:
Careful little partner may have found that the last word hidden gear statement is no longer, now click the Stop button is triggered by this alertview, and the operation of the gear is put in a new method:
Func Alertview (Alertview:uialertview, Clickedbuttonatindex buttonindex:int) { if Buttonindex = = 1 { Loading.stopanimating () } }
The function of Judgment statement is: When we click "Yes" will stop the rotation of the gear, click No effect. Now to test, first click on the download, there are rotating gears:
Then click the Stop button, select No, the gears are still turning, select Yes, the gears disappear.
Swift UI special training Alertview Warning box