Last active
May 9, 2020 13:51
-
-
Save jimbrayrcp/5c0d8316cf4f79888a35833380da7185 to your computer and use it in GitHub Desktop.
Swift 5: iOS: 13.1 Runs a script in another viewController: in this gists example, you can reload data in a TableView from a different ViewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------- VIEW CONTROLLER 1 ----------------------- | |
// MARK: NOTIFICATION | |
extension Notification.Name { | |
static let reload = Notification.Name("reload") | |
} | |
// MARK: CALLER | |
NotificationCenter.default.post(name: .reload, object: nil) | |
// --------------- VIEW CONTROLLER 2 ----------------------- | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// MARK: OBSERVER | |
NotificationCenter.default.addObserver(self, selector: #selector(reloadTableData), name: .reload, object: nil) | |
} | |
// MARK: METHOD | |
@objc func reloadTableData(_ notification: Notification) { | |
tableView.reloadData() | |
tableView.layoutIfNeeded() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use: