[Uikit] uitableview.03

Source: Internet
Author: User

Uitableview.03:

 

[1] drag a uitableview

[2] connect the datasource of tableview to the Controller.

[3] Follow the data source protocol of uitableview <uitableviewdatasource>

[4] add an icon file

[5] Code

 

1. Set the total number of groups. The default value is 1 group. If you do not enter the number, the default value is 1 group.

# How many groups does The Pragma mark return-(nsinteger) numberofsectionsintableview :( uitableview *) tableview {// here the default value is 1, and return 1 is the same as if it is not written ;}

2. Number of rows returned. Nine rows are returned here.

# How many rows does a pragma mark return?-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {return 9 ;}

3. Return the specific data of each row

The following table shows the Arrow styles.

UITableViewCellAccessoryCheckmark
UITableViewCellAccessoryDetailButton
UITableViewCellAccessoryDetailDisclosureButton
UITableViewCellAccessoryDisclosureIndicator
UITableViewCellAccessoryNone
Indicates no
# Pragma Mark returns specific data-(uitableviewcell *) tableview :( uitableview *) tableview labels :( nsindexpath *) indexpath {uitableviewcell * cell = [[uitableviewcell alloc] initwithstyle: Invalid reuseidentifier: nil]; /*********************** set the icon on the left ************ * ****** // 1. obtain the image name nsstring * imagename = [nsstring stringwithformat: @ "0020.d.png", indexpath. row + 1]; // 2. cell. imageview. image = the cell name of the image obtained above. imageview. image = [uiimage imagenamed: imagename]; /*********************** set the main title ************* * ******/[email protected] "12312432 ";
// Set the sub-title. Change the uitableviewcellstyledefault to uitableviewcellstylesubtitle [email protected] "Detailed description"; // the sub-title contains a detailed description. // set the cell arrow style cell. accessorytype = uitableviewcellaccessorycheckmark; return cell ;}

 

4. Set the Row Height for each row

1) join the proxy

2) Add the proxy protocol <uitableviewdelegate>

3) adjust the height

# Pragma mark-adjust the height of each row, proxy method-(cgfloat) tableview :( uitableview *) tableview heightforrowatindexpath :( nsindexpath *) indexpath {// set all heights to 70; return 60; // You can also set different heights based on different input content. // the higher the number of rows, the higher the height. // return 40 + indexpath. row * 5 ;}
 

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.