iOS Learning--uitableview table View cell styles

Source: Internet
Author: User

There are 4 types of UITableViewCell default units:

  1.UITableViewCellStyleDefault
2.UITableViewCellStyleSubtitle
3.uitableviewcellstylevalue1
4.uitableviewcellstylevalue2

To begin with, the default cell uses 3 different elements.

    • Image: If the specified style contains an image, the image is displayed to the left of the text of the cell.
    • text Label: The main text of the cell.
    • Detail Text Label: A unit of auxiliary text, usually used as an explanatory note or label.

How do I use these four kinds of cells? As below, modify the Red section to use one of the cell styles

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {    StaticNSString *simpletableidentifier =@"Simpletableidentifier";UITableViewCell *cell =[TableView Dequeuereusablecellwithidentifier:simpletableidentifier]; if(Cell = =Nil) {        //If there are no reusable cell objects, use the identifier to recreate a cell object.Cell =[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:    Simpletableidentifier]; }        //The default cell contains the picture    cell.imageView.image = [UIImage imagenamed:@ "star1"];           //picture in normal state    cell.imageView.highlightedImage = [UIImage imagenamed:@ "star2"];//picture is selected, highlight State//The default cell contains the text    Cell.textLabel.text = Self.datas[indexpath.row]; //The default cell contains a detailed text label    Cell.detailTextLabel.text = [NSString stringWithFormat:@ "detail%li", indexpath.row+ 1 ]; returncell;}

Run

You can see that the picture is set to a highlighted state, and a different picture is displayed when selected. But why is the headline not in detail?

This is because the style used is uitableviewcellstyledefault, and this style does not show detailed headings. The following are the other 3 different styles of operation:

2.UITableViewCellStyleSubtitle

3.uitableviewcellstylevalue1

4.uitableviewcellstylevalue2, do not display pictures, all text right-aligned, all detailed text left-aligned.

iOS Learning--uitableview table View cell styles

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.