UITableView, iosuitableview

Source: Internet
Author: User

UITableView, iosuitableview

Knowledge point:

1) UITableView

2) UITableViewCell

 

========================================================== ====================

 

1. UITableView

 

1. Introduction to UITableView

UITableView is a list view that inherits UIScrollView

 

2. Common attributes

1) separatorColor split line color

2) separatorStyle split line style

3) separatorInset split line position

3) rowHeight: the height of the cell. The default value is 44.

4) dataSource data source proxy

5) delegate proxy

 

3. reuse mechanism

4. Common proxies

// Set the number of groups

-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView

// Set the number of cells in each group

-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section

// Set the cell content

-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath

// Set the cell height

-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath

// It is automatically transferred when cell is clicked.

-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath

========================================================== ==================

 

Ii. UITableViewCell

 

1. Introduction to UITableViewCell

Each row on UITableView is a UITableViewCell, which is used to display different contents.

2. cell Style

Examples. UITableViewCellStyleDefault, // only one label (that is, the positive title of textLabel) is on the right, and imageView is on the left.

Invalid. UITableViewCellStyleValue1, // two labels. The label on the left (that is, the positive title of textLabel) is black by default and aligned to the left. The label font on the right (that is, the subtitle of detailTextLabel) black by default and right aligned

Invalid. UITableViewCellStyleValue2, // two labels. The label on the left (that is, the positive title of textLabel) is blue by default and aligned to the right. The label font on the right (that is, the subtitle of detailTextLabel) black by default and left aligned

Invalid. UITableViewCellStyleSubtitle // Left aligned label on top and left aligned label on bottom with gray text (Used in iPod ). the top two labels (that is, the positive title of textLabel) are gray by default and align to the left. The label font (that is, the secondary title of detailTextLabel) is gray by default and aligned to the left.

 

3. UITableViewCell attributes (when using the system control in the cell, pay attention to the cell style. If not, it will not be displayed even if it is written)

1) textLabel title

2) detailTextLabel subtitle

3) imageView

4) The image style (UITableViewCellAccessoryNone by default) on the Right of accessoryType is displayed only when the style is set.

/**

UITableViewCellAccessoryNone does not have a style (default)

UITableViewCellAccessoryDisclosureIndicator arrow

UITableViewCellAccessoryDetailDisclosureButton exclamation point and Arrow

UITableViewCellAccessoryCheckmark

UITableViewCellAccessoryDetailButton exclamation point

*/

5) selectionStyle: Click cell to highlight the effect. The specific style is as follows:

/**

UITableViewCellSelectionStyleNone none

UITableViewCellSelectionStyleDefault default, gray

*/

6) cell operations

Delete cell

-(Void) deleteRowsAtIndexPaths :( NSArray <NSIndexPath *> *) indexPaths withRowAnimation :( UITableViewRowAnimation) animation;

Add cell

-(Void) insertRowsAtIndexPaths :( NSArray <NSIndexPath *> *) indexPaths withRowAnimation :( UITableViewRowAnimation) animation;

Mobile cell

-(Void) moveRowAtIndexPath :( NSIndexPath *) indexPath toIndexPath :( NSIndexPath *) newIndexPath

Refresh

-(Void) reloadRowsAtIndexPaths :( NSArray <NSIndexPath *> *) indexPaths withRowAnimation :( UITableViewRowAnimation) animation

4. Differences between the group header and the header

Proxies are required for displaying the group header or tail.

-(UIView *) tableView :( UITableView *) tableView viewForHeaderInSection :( NSInteger) section

-(UIView *) tableView :( UITableView *) tableView viewForFooterInSection :( NSInteger) section

// The viewForHeaderInSection or viewForFooterInSection proxy is called only when the height of the group header or tail is set.

-(CGFloat) tableView :( UITableView *) tableView heightForHeaderInSection :( NSInteger) section

-(CGFloat) tableView :( UITableView *) tableView heightForFooterInSection :( NSInteger) section

Response. UITableViewHeaderFooterView attributes

1) textLabel title

2) detailTextLabel subtitle

Rule. The table header (tableHeaderView) has only one header, and the height is determined by the currently created view. The width is determined by tableView.

 

5. Other common proxies of tableView

1) return the group header title

-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section

 

2) return the title at the end of the Group

-(NSString *) tableView :( UITableView *) tableView titleForFooterInSection :( NSInteger) section;

3) whether to allow editing. By default, all settings can be edited.

-(BOOL) tableView :( UITableView *) tableView canEditRowAtIndexPath :( NSIndexPath *) indexPath

 

4) modify the text on the delete button

-(NSString *) tableView :( UITableView *) tableView titleForDeleteConfirmationButtonForRowAtIndexPath :( NSIndexPath *) indexPath

 

5) EDIT status. This proxy can be deleted or inserted (operations can be performed by determining the editingStyle type)

-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath

 

6) // 8.0 new proxy method

// Multiple buttons (delete, pin to top, and more) appear when the left cell is set at the same time)

// If this proxy method is implemented, the built-in deletion will be lost.

-(UITableViewCellEditingStyle) tableView :( UITableView *) tableView editingStyleForRowAtIndexPath :( NSIndexPath *) indexPath

// Use the following method to create a button

+ (Instancetype) rowActionWithStyle :( UITableViewRowActionStyle) style title :( nullable NSString *) title handler :( void (^) (UITableViewRowAction * action, NSIndexPath * indexPath) handler;

 

7) the mobile cell proxy can be moved only after the proxy is implemented.

-(Void) tableView :( UITableView *) tableView moveRowAtIndexPath :( NSIndexPath *) sourceIndexPath toIndexPath :( NSIndexPath *) destinationIndexPath

 

8) Return Index

-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView

[Note] UITableViewIndexSearch search icon

 

9) control indexes

-(NSInteger) tableView :( UITableView *) tableView sectionForSectionIndexTitle :( NSString *) title atIndex :( NSInteger) index

[Remarks]-1 is returned, and nothing is done.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

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.