Different types of TableView in iOS

Source: Internet
Author: User

Different types of TableView in iOS

TableView is a frequently used View in iOS development. For different display requirements, we need different cells for display. For more complex display, we usually customize the Cell style, however, you can simply display the list types supported by iOS.

Currently, iOS supports the following list types:

UITableViewCellStyleDefault: default type, which can display images and text UITableViewCellStyleSubtitle: displays images, text, and sub-text UITableViewCellStyleValue1: displays images, text, and sub-text UITableViewCellStyleValue2
Their display styles are also different, as shown in the following order: it is easy to set, the Code is as follows:
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell; // there are four types of switches (indexPath. row) {case 0: // UITableViewCellStyleDefault: default type. images and text can be displayed. {NSString * CellOne = @ "CellOne "; // set tableview type cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellOne]; // you cannot click cell. selectionStyle = UITableViewCellSelectionStyleNone; cell. imageView. image = [UIImage imageNamed: @ "icon"]; // image cell. textLabel. text = @ "textLabel"; // text} break; case 1: // UITableViewCellStyleSubtitle type, supports displaying images, text, and subtexts {NSString * CellTwo = @ "CellTwo "; // set tableview type cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: CellTwo]; // you cannot click cell. selectionStyle = UITableViewCellSelectionStyleNone; cell. imageView. image = [UIImage imageNamed: @ "icon"]; // image cell. textLabel. text = @ "textLabel"; // text cell. detailTextLabel. text = @ "detailTextLabel"; // subtext} break; case 2: // UITableViewCellStyleValue1 type. It supports displaying images, text, and subtext {NSString * CellThree = @ "CellThree "; // set tableview type cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: CellThree]; // you cannot click cell. selectionStyle = UITableViewCellSelectionStyleNone; cell. imageView. image = [UIImage imageNamed: @ "icon"]; // image cell. textLabel. text = @ "textLabel"; // text cell. detailTextLabel. text = @ "detailTextLabel"; // subtext} break; case 3: // UITableViewCellStyleValue2 type; supports displaying text and subtext {NSString * CellFour = @ "CellFour "; // set tableview type cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue2 reuseIdentifier: CellFour]; // you cannot click cell. selectionStyle = UITableViewCellSelectionStyleNone; cell. textLabel. text = @ "textLabel"; // text cell. detailTextLabel. text = @ "detailTextLabel"; // subtext} break;} return 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.