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) {
super.viewWillAppear(true)
//perform api call if any
yourTableView.reloadData()
}
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) {
super.viewWillAppear(true)
//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() {
super.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) {
self.Table.reloadData()
/// Table is IBoutlet name of your tableview
}
OR You can use on Controller B
override func viewWillAppear(_ animated: Bool) {
self.Table.reloadData()
}
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 UIView
s:
- KVO
- Notifications
- 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() {
super.viewDidLoad()
...
NotificationCenter.default.addObserver(self, selector: #selector(reloadTableViewData), name: NSNotification.Name(rawValue: "reloadData"), object: nil)
}
@objc func reloadTableViewData() {
tableView.reloadData()
}
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!
fav.reloadData()
Related Topics
Generate .Pem File Used to Set Up Apple Push Notifications
How to Check When a Uitextfield Changes
Can You Build Dynamic Libraries For iOS and Load Them At Runtime
Programmatically Retrieve Memory Usage on Iphone
Seeing Black Bars At the Top and Bottom of the Iphone X Simulator
Fatal Error: Unexpectedly Found Nil While Unwrapping an Optional Values
Nsfilemanager.Defaultmanager().Fileexistsatpath Returns False Instead of True
Objective-C Arc: Strong VS Retain and Weak VS Assign
How to Check If a String Contains Another String in Objective-C
Ios 8 Uitableview Separator Inset 0 Not Working
Uiscrollview Scrollable Content Size Ambiguity
Programmatically Set the Initial View Controller Using Storyboards