Created
June 12, 2016 12:55
-
-
Save amlcurran/ebc38dff5d2ab4deb14d39a68e509687 to your computer and use it in GitHub Desktop.
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
class FirstViewController: UIViewController, UITableViewDelegate { | |
private let items : [String] = [ /* some items */] | |
private let tableView = UITableView() | |
/* lots of other methods */ | |
override func viewDidAppear(animated: Bool) { | |
super.viewDidAppear(animated) | |
tableView.delegate = self | |
} | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
let item = items[indexPath.row] | |
navigationController?.pushViewController(SecondController(item: item), animated: true) | |
} | |
} |
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
class FirstViewController: UIViewController { | |
private let items : [String] = [ /* some items */] | |
private let tableView = UITableView() | |
/* lots of other methods */ | |
override func viewDidAppear(animated: Bool) { | |
super.viewDidAppear(animated) | |
tableView.delegate = self | |
} | |
} | |
extension FirstViewController: UITableViewDelegate { | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
let item = items[indexPath.row] | |
navigationController?.pushViewController(SecondController(item: item), animated: true) | |
} | |
} |
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
class FirstViewController: UIViewController { | |
private let items : [String] = [ /* some items */] | |
private let tableView = UITableView() | |
private var delegate : UITableViewDelegate! | |
/* lots of other methods */ | |
override func viewDidAppear(animated: Bool) { | |
super.viewDidAppear(animated) | |
delegate = GoToDetailsDelegate(controller: navigationController!, items: items) | |
tableView.delegate = delegate | |
} | |
} | |
class GoToDetailsDelegate: NSObject, UITableViewDelegate { | |
let controller : UINavigationController | |
let items : [String] | |
init(controller: UINavigationController, items: [String]) { | |
self.controller = controller | |
self.items = items | |
} | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
let item = items[indexPath.row] | |
controller.pushViewController(SecondController(item: item), animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment