Swift: Reload a View Controller

How to reload present view controller swift?

FirstViewController calling 2nd view controller

@IBAction func CallSecondViewButton(_ sender: Any) {

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "YourViewControllerIdentifier") as! YourViewController

controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)


just write the code in viewWillAppear() method of the view controller that you want to reload like this

override func viewWillAppear(_ animated: Bool) {

//perform api call if any


2nd view controller

@IBAction func CloseButton(_ sender: Any) {

self.dismiss(animated: true, completion: nil)


after dissmissing the viewWillAppear method of firstViewController will autometically called.
The First two snippets are for first view controller and the last one is for second view controller

How reload view controller like first time in Swift?

Assign data to the ViewController or making API calls inside viewWillAppear that will call everytime when you came to that viewcontroller. Only you have to do to call data population functions/API call inside viewWillAppear

override func viewWillAppear(_: Bool) {

//call your data populating/API calls from here


Hope this will help you

How to reload UIViewController from another Controller in swift 5

By using a simple notification

Add this on submit button action (Controller A)

NotificationCenter.default.post(name: Notification.Name("reloadTable"), object: nil)

add this Controller B viewdidload()

override func viewDidLoad() {

NotificationCenter.default.addObserver(self, selector: #selector(
self.reloadMyTable(notification:)), name: Notification.Name("reloadTable"),
object: nil)

Now add this function somewhere on Controller B

@objc func reloadMyTable(notification: Notification) {


/// Table is IBoutlet name of your tableview

OR You can use on Controller B

    override func viewWillAppear(_ animated: Bool) {

Reloading a ViewController

You really don't need to do:

[self.view setNeedsDisplay];

Honestly, I think it's "let's hope for the best" type of solution, in this case. There are several approaches to update your UIViews:

  1. KVO
  2. Notifications
  3. Delegation

Each one has is pros and cons. Depending of what you are updating and what kind of "connection" you have between your business layer (the server connectivity) and the UIViewController, I can recommend one that would suit your needs.

How to reload ViewController from another class?

You must call reloadData() in self, the view controller that manages the table view.
Luckily, you can use notification to achieve calling the relevant function from another class.
In the view controller

override func viewDidLoad() {
NotificationCenter.default.addObserver(self, selector: #selector(reloadTableViewData), name: NSNotification.Name(rawValue: "reloadData"), object: nil)

@objc func reloadTableViewData() {

In your class IAPObserver, use the following to notify that you now want to reload data:

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadData"), object: nil)

reload tableView from Another ViewController Swift 4.2

Thanks for every one.Finally after a R&D. i found the following solution. and its working fine.

let fav:FavoritesFiltersViewController! 

Related Topics

Leave a reply