How do I use TableView to display a UITableViewCell or subclass created in a custom nib?

Source: Internet
Author: User

1. Create a nib file Cell.xib

2. Drag a uitableview out of the nib, set its reuse Identifier, and then drag the view to the cell UI to place

3. Creating Viewcontroller and TableView

4. Create the TableView in Viewcontroller (iboutlet) TableView

5. Set TableView delegate and DataSource (if the runtime finds all table cells to be blank, it is likely that this step has been forgotten)

6.viewDidLoad Register nib file (TableView registernib:)

7. Let Viewcontroller follow TableView's <uitableviewdatasource, uitableviewdelegate> protocol

8. Implementing the Protocol Approach

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView;

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath

which

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

If you take advantage of Dequeuereusablecellwithidentifier:forindexpath, you do not need to determine if the cell is nil and then create it, because this method

A new object is created in the multiplexing queue without a file or class that can be automatically called for registration.

If you want to respond to clicking on a cell, you need to implement-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath

How do I use TableView to display a UITableViewCell or subclass created in a custom nib?

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.