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 ;}