How to Completely Reload a View So That Viewdidload Gets Run Again

How can I completely reload a view so that viewDidLoad gets run again?

viewViewDidLoad and viewWillAppear are part of the view controller lifecycle and are called automatically by iOS after your UIViewController got instantiated and before the view appears on the screen. You can call them anywhere in your view controller class, but that's not at all good practice and I would never recommend you to do so!

If you have code that you want to be executed at multiple times during the lifetime of your view controller, put it into separate methods and call these from viewDidLoad and from the other parts in your code where you need them.

You can read more about the view controller life cycle in Apple's documentation.

A way to reload the ViewDidLoad on each run swift

Set your view controller to listen applicationDidBecomeActive notifications and run the configuration method when it receives it

NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "refreshView:",
name: UIApplicationDidBecomeActiveNotification,
object: nil)

How to reload a previous page when segue back

Use viewWillAppear method for that.

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 can I reload a view controller once I have signed into Parse

I would just check if the value of the Bool Variable has changed, and if it does then run the viewDidLoad() method.

To check if a value is changed in a Bool run the willSet method as such:

var myBool: Bool = Bool() {

willSet {

println("the value of the variable has changed")
viewDidLoad()

}

}

this code that I wrote automatically checks if the value of the variable changes, and if it does then it will run the code in the willSet method. in this case it will run the viewDidLoad() statement again and print: "the value of the variable has changed".

I am assuming that the viewDidLoad(), when refreshed, will reset the content settings and make sure the user has access to whatever he/she needs access to.

Also if you are just having trouble reloading the viewDidLoad() method than just run the viewDidAppear method:

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)

viewDidLoad()

//OR JUST RELOAD THE CONTENT SETTINGS
}

How to refresh UITableView with reloadData() on ViewDidAppear?

You are reloading the table, but you're not repopulating the remindersArray. Remember to re-retrieve the data from NSUserDefaults before calling reloadData.

how can i refresh the content of a view before I popViewController?

-(void)viewWillAppear:animated

Not sure if its called before [self.navigationController popViewControllerAnimated:YES]; but certainly before you see the view. Make a call to reload your map's annotations in it.

Also make sure to call viewWillAppear super.

If both view are not working form the same data object you'll need a delegate to send the data back.

iOS: How to Refresh a UIViewController after Popping its Child UIViewController?

Take a look at NSNotification - thats an easy way to send updates from one part of your code to another is Apple’s built-in NSNotification system.

  1. If you have an update you want to send, you call postNotificationName. You just give it a unique string you make up (such as “com.razeware.imagegrabber.imageupdated”) and an object (such as the ImageInfo that just finished downloading its image).

  2. If you want to find out when this update happens, you call addObserver:selector:name:object. In our case the ImageListViewController will want to know when this happens so it can reload the appropriate table view cell. A good spot to put this is in viewDidLoad.

  3. Don’t forget to call removeObserver:name:object when the view gets unloaded. Otherwise, the notification system might try to call a method on an unloaded view (or worse an unallocated object), which would be a bad thing!
    via Ray Wenderlich blog

Swift Reload CurrentView

As far as I know you cannot 'reload' the viewController (Please correct me if I am wrong).

What are you trying to reload? Is it something specifically? It looks like you are checking for internet connection, right?

What I reccommend is, in your viewDidLoad take everything out and put it in a function, for example stuffToLoad()

Then, call that function in your ViewDidLoad. Run the app, does everything still work the way it is supposed to? If so that means you can now use:

SwiftSpinner.show("Please connect to the internet, and try again").addTapHandler({
SwiftSpinner.hide({
self.stuffToLoad()
})
}, subtitle: "Tap to try again..")


Related Topics



Leave a reply



Submit