Swift 4.0 Pure Code Implementation UITableView

Source: Internet
Author: User
Class Viewcontrolleri:uiviewcontroller,uitableviewdelegate,uitableviewdatasource {var mytableview:uitableview? Let testvalue:nsstring = "This is the test content \ n This is the test content \ n This is the test content \ n This is the test content \ n This is the test content \ n This is the test content \ NAND This is the test content \ n This is the test content \ n This is the test content \ n This is the n This is the test content \ n This is the test content \ n This is the test content "override Func Viewdidload () {super.viewdidload () View.backgroundcolor = UI Color.gray Mytableview = UITableView (Frame:cgrect (x:0, y:64, Width:view.frame.width, Height:view.frame.heigh T), style:. Plain) Mytableview? Tablefooterview = UIView () Mytableview? delegate = self//set agent Mytableview? DataSource = Self Mytableview?. Estimatedrowheight = Mytableview?

        RowHeight = Uitableviewautomaticdimension view. Addsubview (mytableview!) Register Uitableview,cellid for identifier Mytableview with cell reuse? Register (uitableviewcell.self, Forcellreuseidentifier: "Cellid")}/* Note: Our front Viewcontroller inherits UITableView
DataSource     @ and Uitableviewcelegate.
     If we do not register the following three methods Xcode will be an error ... *///Column number Func numberofsections (in Tableview:uitableview)-> Int {return 1}//number of rows func TableView (_ Tableview:uitableview, numberofrowsinsection section:int)-> Int {return 10}//Create Uitable

        Viewcell Func TableView (_ Tableview:uitableview, Cellforrowat indexpath:indexpath)-> UITableViewCell { Let cells = (Tableview.dequeuereusablecell (withidentifier: "Cellid", For:indexpath)) as UITableViewCell Cells.tex Tlabel? Text = TestValue as String return cells}//Click Response Event Func TableView (_ Tableview:uitableview, DIDs Electrowat Indexpath:indexpath) {tableview.deselectrow (At:indexpath, Animated:true)}//Split Line no spacing o Verride func viewdidlayoutsubviews () {Mytableview? Separatorinset =. Zero Mytableview? Layoutmargins =. Zero} func TableView (_ Tableview:uitableview, Willdisplay cell:uitableviewcell, Forrowat indexpath:indexpath) {cell.separatorinset =. Zero cell.layoutmargins =. Zero}
 

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.