Use of the "iOS development" UITableView

Source: Internet
Author: User

UITableView is what we use to show the data, his use is very extensive, but also the most used controls, let's look at his simple use.

Uitabelview itself with Uiscrollview, so more data, he is automatic scrolling.

To display data in Uitabelview, you must have a data source, that is, let Viewcontroller implement the <UITableviewDataSource> protocol.

@interface Viewcontroller () <UITableViewDataSource>
1. You can use the connection method
2.self.tableview.delegate = self;

The following three methods are then implemented in this Protocol.

1. Returns a total of several sets of data.

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {    return 1;}

2. Returns a few rows per group

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {    return Self.heros.count;}

3. Show the data for each row

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {   static NSString *id = @ "Hero";        UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:id];    if (cell = = nil) {        cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier:id];< c6/>}    Hero *hero = Self.heros[indexpath.row];        Cell.textLabel.text = Hero.name;    Cell.detailTextLabel.text = Hero.intro;    Cell.imageView.image = [UIImage ImageNamed:hero.icon];        return cell;}

This is uitableview simple to use!

Use of the "iOS development" UITableView

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.