Is it possible to reload/update a viewController's view once a file gets saved in the documents folder? If yes, kindly suggest how to accomplish this.
I'm trying to save a file in AppDelegate, but as it involves XML parsing, it is saved only when a view gets loaded. This is the view that is supposed to show the contents of the file. But as it gets loaded before the file is saved, the view doesn't display anything.
This query is related to my question at this link
Shall I share the code here again?
I can guide you through the process. What you need to implement is:
Notification
throughNotificationCenter
. (Additionally you can check for the existence of the file immediately before posting theNotification
).observer
for listening to thatNotification
throughNotificationCenter
in yourViewController
(maybe insideviewDidLoad()
).observer
you need to specify aselector
(method) which will be called when the notification occurs. So add a method and provide it as theselector
for addObserver.view
dirty. It is usually done withself.view.setNeedsDisplay()
. This will do the reloading/updating part.Here I'm posting relevant code. Focus on the comments inside the code.
AppDelegate.swift
ViewController.swift
CustomXMLParser.swift