Skip to content

Instantly share code, notes, and snippets.

@MochaTheCoder
Last active May 9, 2019 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MochaTheCoder/628af8950f39e5fc0896cc12d77c6fb2 to your computer and use it in GitHub Desktop.
Save MochaTheCoder/628af8950f39e5fc0896cc12d77c6fb2 to your computer and use it in GitHub Desktop.
reloadData Handler cellForRowAt debug
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let aVC = AViewController()
let nav = UINavigationController(rootViewController: aVC)
window!.rootViewController = nav
window!.makeKeyAndVisible()
return true
}
import UIKit
class BViewController: UIViewController {
@IBOutlet var handlerButton: UIButton! {
didSet {
handlerButton.addTarget(self, action: #selector(doHandler), for: .touchUpInside)
}
}
var handler: (() -> Void) = {}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("Disappearing")
}
@objc private func doHandler() {
handler()
}
}
import UIKit
class AViewController: UIViewController {
@IBOutlet var pushButton: UIButton! {
didSet {
pushButton.addTarget(self, action: #selector(pushBVC), for: .touchUpInside)
}
}
@IBOutlet var tableView: UITableView! {
didSet {
tableView.dataSource = self
}
}
@objc private func pushBVC() {
let bVC = BViewController()
bVC.handler = {
print("handling")
self.tableView.reloadData()
}
navigationController?.pushViewController(bVC, animated: true)
}
}
extension AViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("CellForROwAt")
return UITableViewCell()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment