I want to call table.reloadData() when I dismiss my UIAlertController. But I don’t know how to do it.
I tried putting table.reloadData() in ViewController’s viewWillAppear but it doesn’t work because Alert’s modalPresentationStyle cannot be changed.
I’m presenting alertController like so:
`let alert = UIAlertController(title: "Some Title", message: "Enter a text", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak alert] (_) in
let enteredTitle = alert!.textFields![0]
let enteredNoteDescription = alert!.textFields![1]
//Save to DB
let note = Note(context: CoreDataService.managedObjectContext)
note.title = enteredTitle.text
note.noteDescription = enteredNoteDescription.text
CoreDataService.saveContext()
}))
present(alert, animated: true, completion: nil)`
2
Answers
Usage is:
I’ve tried this solution and worked with me:
Suppose that your data source is:
and then your alert creation be like this:
So As you see I’ve reloaded the table view in the action handler completion using self?.tableView.reloadData() and the worked fine with me.
let me know if it didn’t work with you