IPhone development application-Table view learning case

Source: Internet
Author: User

IPhone DevelopmentApplication in progressTable ViewIs the content of this article, mainly to learnTable ViewFor more information, see.

1. Concepts

Table view is the most common mechanism used to display data lists to users. They are highly configurable objects and can be configured in any form required by users. The iPhone can have only one column

2. Basic table View

A table is used to display the data list. Each item in the data list is represented by a row.

Table view is a view object that displays table data. It is an instance of the UITableView class. Each visible row in the table is implemented by the UITableViewCell class. Therefore, table view is an object that displays the visible part of the table, the table view unit displays a row in the table.

Table view obtains configuration data from objects that follow the UITableVieDelegate protocol and type data from objects that follow the UITableViewDataSource protocol.

3. Grouping and unformatted tables

Each group in the grouping table consists of multiple rows embedded in the rounded rectangle. Note that a grouping table can contain only one group.

Format-free table: This is the default format. Any table without the rounded rectangle attribute is a format-free table view.

Note: If the data source provides necessary information, you can use the index on the right to navigate the list through the table view.

Each part of the table is called a partition in the data source. In the grouping table, each group is a partition.

4. Method

  1. -NSInteger) tableView :( UITableView *) tableView numberofRowsInsection :( NSInteger) section {
  2. Return [self. Your array name count];
  3. }

Used to view the number of rows in a specified partition

  1. - UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{  

This method is called when one row needs to be drawn in the table view. The second parameter is an NSIndexPath instance. The table view uses this mechanism to bind partitions and rows to an object.

5. Remember

Each row in the table has a UITableViewCell instance. This instance is a subclass of UIView, which means that each row can have a subview. Some table view units left the screen as a result of the scroll operation will be placed in a reusable unit sequence. If the system runs slowly, the table view will delete these units from the sequence, to release space. However, as long as there is available storage space, the table view will obtain these units again.

6. Table view Unit style

Unit styles use three different unit elements:

1) image: if the specified style contains an image, the image will be displayed on the left side of the unit text

2) text Tag: unique text displayed in Cells

3) detailed text Tag: the auxiliary text of a unit, which is usually used as an explanatory description or tag.

7. Set the indent level

  1. #pragma mark -  
  2. #pragma mark Table Delegate Methods  
  5. - (NSInteger)tableView:(UITableView *) tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{  
  6.   NSUINteger row = [indexPath row];  
  8. return row;  
  9. } 

Set the indentation level of each row to its row number. Therefore, the indentation level of the 0 row is 0, and the first behavior is 1.

8. Processing row: specify that the specified row has no response

  1. - NSIndexPath *)tableView:(UITableView *)tableView willselectRowAtIndexPath:(NSIndexPath *)indexPath{  
  2. NSUInteger row = [indexPath row];  
  4. if(row == 0)  
  5. {  
  6. return nil;  
  7. }  
  8. return indexPath;  

Our Code focuses on which row will be selected. If this row is the first row and Its Index will always be 0, it will return nil, indicating that no row is actually selected. Otherwise, it returns indexPath, indicating that you can continue with the selection.

9. Change the font size and Row Height.

1) change the size:

  1. cell.textLabel.font = [UIFont boldSystemFontOfSize:50]; 

2) Change the Row Height:

  1.  - CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{  
  2. return 70;  

10. Add an index

  1. -NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {
  2. Return keys; // here, keys are an attribute of my project.
  3. }

11. Add a search bar

Create two new dictionaries: an unchangeable dictionary that contains the complete dataset, and a variable dictionary copy that can delete rows from it.

The delegate and data source will be read from the variable dictionary. When the search criteria change or cancel the search, you can refresh the variable dictionary from the unchangeable dictionary.

Summary:IPhone DevelopmentApplicationTable ViewI hope this article will help you with the introduction of the Learning case!

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.