Uialert wird nicht abgewiesen, wenn die Addaktion verwendet wirdIOS

Programmierung für iOS
Guest
 Uialert wird nicht abgewiesen, wenn die Addaktion verwendet wird

Post by Guest »

Ich implementiere eine Popup -Warnmeldung bei Synchronisation von Daten. Es verschwindet, wenn der Synchronisationsprozess wie erwartet abgeschlossen ist. Wenn ich dem Popup jedoch eine Abbrechen-Taste hinzugefügt habe, wird das Popup nicht abgewiesen, es sei denn, es wird vom Benutzer aktiviert. Auch wenn die Schaltfläche vorhanden ist, ist der präsentierteViewController nicht mehr die Warnung (gemäß der nachstehenden Codeprüfung), sondern wird für den Benutzer angezeigt und aktiv. Wenn ich die Schaltfläche weglässt, gibt die folgende Codeprüfung an, dass es sich um den präsentiertenViewController handelt. Irgendwelche Ideen? < /P>

Code: Select all

DispatchQueue.main.async {
let alert = UIAlertController(title: "Syching Data", message: "This may take a few seconds...", preferredStyle: .alert)
//alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) // this prevents dismiss below
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)}))
print("** PRESENT Alert")
self.present(alert, animated: true, completion: nil)
//DispatchQueue.global().async { // runs sync in background - NOT needed
Task {
deviceSyncTime = 0 // temporary bypass
let zoneid = detZoneID(zName: fileC, zonesIn: privateZones)
let chkDone = await fetchNewRecords(starttime: deviceSyncTime, db: db, zonename: zoneid)
actLog(newPrint: "ManageF Cloud Records fetched:" + String(describing: chkDone.count))
let privateSync = await processSync3(db: db, recordA: recordsLoad, cloudStruct: chkDone)
processTrigger = "On"
updateFileZ3REM(newRecordUps: privateSync, dbase: db, inArray: recordsLoad)  {result in
if result == true {
print("manageF, updateFileZ result= true")
DispatchQueue.main.async {
if self.presentedViewController == alert {
alert.dismiss(animated: true, completion: nil)
print("** DISMISS called")  // This executes when Cancel button is omitted
} else {
print("** ALERT is not presented controller") // This print is executed when Cancel button is present
}
print("** Trying to dismiss alert controller")
alert.dismiss(animated: true, completion: nil) // This does not execute when Cancel button is present
} // end main async
if let findex = fileToBeUpdated.firstIndex(of: fileNN) {
fileToBeUpdated.remove(at: findex)
}
} else {
print("manageF, updateFileZ result= NOT true")
}
}
print("end task")
} //end task
print("end async op")
//} // async
print("end main thread")
} // main thread

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post