[help wanted] Transition from TableView Cell Example
Closed this issue · 5 comments
Hi,
first thanks to the truly cosmic mind Danial Dahan bringing such a wonderful collection of really helpful frameworks to the world!
As I don't manage it to successfully submit Stackowerflow questions (doh), I ask either for help or an extension of the Graph Search and/or the PresenterCard sample projects:
Could you please show an example of how to transition from a cell to another VC using
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
?
Or would a transition from a cell only be possible using a button? As the individually setup TableViews are their own delegates and don't know of e.g. a navigation controller/the push method and I don't know how to use the Material-normal transition method here, I'd be glad to find out via a code example how to achieve this.
Thanks and best wishes,
Karsten
Ok, I'll answer the question on my own: at least one solution is the classic delegation way:
Assume you have a RootViewController wich uses a UserTableView for displaying search results (as in https://github.com/CosmicMind/Samples/tree/master/Projects/Programmatic/Search).
From clicking on a result tableView cell you want to navigate to a newly created PersonDetailViewController.
Despite of being the UserTableView its own TableViewDelegate you shift this responsibility (and the extension to the RootViewController.
Then you can:
extension RootViewController: TableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
navigationController?.pushViewController(PersonDetailViewController(), animated: true)
}
}
Remember to set
tableView.delegate = self
in the RootViewController and remove it from UserTableView!
Hey :), thank you for the support? Nice answer, and a correct one as well. Generally it takes at most a day for me to respond. I appreciate you sharing the answer on this issue :)
Hey Daniel,
what an honor receiving your kind reply here, thanks a bunch!
Nice answer, and a correct one as well.
Thanks for the hint moving delegation is the right approach.
I can imagine that for Material starters it could be useful to have more levels of navigation in the samples. E.g. every button, every cell could have a target.
The target could be the same final view, e.g. one with some "marketing" for Material and the other amazing CosmicMind frameworks ;)
You are 100% correct. I am working on a tool to bring more knowledge to everyone, starting with CosmicMind's frameworks. So please feel free to ask for any help and soon you will have more to learn from :)
That sounds fantastic!
Let's see when I have a question I can't answer by myself - thing is that most of the problems I can solve on my own using the samples which are generally pretty complete.