IOS Tableviewcontrollertableviewcontroller---Classes with controllers are standard MVC pattern TableView use:----Tableviewcontroller subclasses, Only Viewtableview and his type: The TableView control can control tableview by writing its own subclass that inherits from TableView, as long as the tableview is associated with the control, set in storyboard,about TableView can see other notesThe following code is written tableview when you need to write the method import Uikit//uitableviewdatasource for TableView to provide data related operations, uitableviewdelegate and list to interact with, Delegate is mainly used for the display of dataclass Mytv:uitableview, Uitableviewdatasource, uitableviewdelegate{
Let Tag_label = 1 var data:nsdictionary! This paragraph is initialized from storyboard need to join this section .... For required required init (coder Adecoder:nscoder) {super.init (coder:adecoder) data = Nsdictionary (Contentso FURL:NSBundle.mainBundle (). Urlforresource ("Data", Withextension: "plist")!) Bundle, initialize a variable with a file, this initialization is written by the DataSource file name self.datasource = self;//provide yourself with data self.delegate This also needs to be initialized at load time}//returns the number of sections Func Numberofsectionsintableview (Tableview:uitableview), Int { return data.count//This data is section-level}//Specific line gets UITableViewCell func tableView (Tableview:uitableview, cell Forrowatindexpath Indexpath:nsindexpath), UITableViewCell {//This parameter cell is the reuse ID specified by Tableviewcell, and this cell has a T The AG is set to a label of 1, and the function returns a reusable Table-view cell object located by its identifier. var cell:anyobject! = Tableview.dequeuereusablecellwithidentifier ("cell") var label = Cell.viewwithtag (Tag_label) as UILabel
//The value is stored in the array by section first, and the row value in the section is converted to string
label.text! = ((Data.allvalues[indexpath.section]). Objectatindex (Indexpath.row) as String) return cell as UITableViewCell} Seciton Header title Func TableView (Tableview:uitableview, Titleforheaderinsection section:int), String? {return data.allkeys[section] as? String}//section The number of row in Func TableView (Tableview:uitableview, Numberofrowsinsection section:int), Int { Return (Data.allvalues[section]). Count//The number of rows of all values corresponding to the section}
A single cell is selected after the processing event func TableView (Tableview:uitableview, Didselectrowatindexpath indexpath:nsindexpath) {print ln ("\ (Data.allvalues[indexpath.section].objectatindex (indexpath.row)) Clicked")}}
Seciton for iOS
iOS Learning essay two