iOS Learning Essay II

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.