Swift 2.0 custom cell and different style of cell

Source: Internet
Author: User

Yesterday we wrote about using the system cell how to create TableView, today we subdivide, is the different style of cell, how we write code. Create a cell yourself, inherit from UITableViewCell we'll see how the code in the cell is written.

Import Uikitclass Hometableviewcell:uitableviewcell {//We simply add a picture on this cell to let Oneimage:uiimageview = UIImage View ()//overriding initialization method override Init (Style:uitableviewcellstyle, reuseidentifier:string?)            {Super.init (Style:style, Reuseidentifier:reuseidentifier)//Create UI Method Creatui ()    }//This method is also necessary to implement, and the overriding initialization method is implemented together. Required init? (Coder Adecoder:nscoder)    {FatalError ("init (coder:) have not been implemented")}//method to create the UI, only a simple picture is written here.                Func Creatui () {oneimage.frame=cgrectmake (0, 0, self.contentView.bounds.width, self.contentView.bounds.height) Self.contentview. Addsubview (Oneimage)} override func awakefromnib () {Super.awakefro Mnib ()//initialization Co} override Func setselected (Selected:bool, animated:bool) {Supe R.setselected (selected, animated:animated)//Configure The view for the selected state}}

Here's the code for the controller's face.
Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UITableViewCell {                if ( Indexpath.section! = 1)        {            //System cell let            Cell:uitableviewcell = Tableview.dequeuereusablecellwithidentifier ("Swiftcell", Forindexpath:indexpath)            Cell.textlabel? Text= "You are really handsome"            return cell        }        else        {            //Custom cell let            Cellone:hometableviewcell = Hometableviewcell ()            cellone.oneImage.image = UIImage (named: "Screen shot")            return CellOne                    }            }

This is complete, and we'll take a closer look.


Swift 2.0 custom cell and different style of cell

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.