Tag:ios swift Stanford Open Class tableview delegate
The previous remark introduced TableView's DataSource, which introduces another important part of delegate.
When we click on a cell, how do we jump to another MVC?
Like adding other segue, click the cell Control key, right-connect to another MVC, then let go, select the desired segue type.
If you have other buttons on your cell, such as detail disclosure, you can also select its segue:
Then set your segue:
Then go to Prepareforsegue to set this segue:
Each case corresponds to a different identifier, note that the sender here is of the anyobject type.
To get a sender's message in prepare, or to convert the sender to its original type, these methods in prepare do not accept a anyobject type parameter.
Then provide the data to the target controller:
Let's talk about delegate:
Delegate will observe the dynamics of tableview, such as cell being clicked. When segue is not applicable, you can use this proxy method to implement the jump:
There are many other ways to delegate:
If your model changes, remember to call the Reloaddata method to update the view.
Because when the view is displayed, the two number method and the Cellfor method have been called, we need to update the view with the Reloaddata method when the model changes, this method is a heavyweight method that will update all the data, if you just change a part of the data, You can use the lightweight approach:
Reloadrowsatindexpaths.
The height of each row in the TableView must be specified, or it can be done through automatic layout. You can also set the height of the row by using the proxy method.
In addition to the proxy method, here are some ways to tableview your own:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"We all love Paul Hegarty" Stanford IOS8 public class personal note TableView Delegate