Uitableviewcontroller&uitableview of iOS Learning notes

Source: Internet
Author: User

Uitableviewcontroller&uitableview of iOS learning noteswrite in front

Until the end of last month, I have been busy with the lab, and after discussing it with the instructor, I find that the work done in the lab is not enough to write a dissertation, so we need to continue thinking about the new algorithm. This is a painful thing to do, especially when it is difficult to find documents related to the direction of your research. Perhaps the research significance of the grid sequence watermark is still to be verified. Still, try to think it through. Because of lab reasons, the learning progress of iOS is obviously affected, and the collation of the document itself is a time-consuming and energetic thing, so it took so long not to write notes.

Introduction to MVC

Before introducing UITableView, simply introduce the MVC (Model-view-controller) pattern, which is a design pattern followed by iOS development. The implication is that any object created by the app must be of one of the following three types

    • Model: Responsible for storing data, regardless of user interface

    • View: Responsible for display interface, regardless of model object

    • Controller: Responsible for ensuring consistent data for view objects and model objects

UITableView Introduction

UITableView is a view, so UITableView is not responsible for processing the logic or data of the application, and when actually using UITableView, consider the following issues:

    • Typically, you create and release UITableView objects through a view control object and are responsible for showing or hiding the view

    • uitableview object needs to have data source to work correctly. The UITableView object queries the data source for the functions to be displayed, the data needed to display the table rows, and other required data. Any OC object that complies with the Uitableviewdatasource protocol can be called a data source for the UITableView object.

Uitableviewcontroller Introduction

The Uitableviewcontroller object can play all the roles required by the above UITableView, including view control objects, data sources, and delegate objects.
Uitableviewcontroller is a subclass of Uiviewcontroller and therefore has its own view property. The View property of the Uitableviewcontroller object points to a UITableView object, and the UITableView object is set and displayed by the Uitableviewcontroller object. The Uitableviewcontroller object assigns a value to the DataSource and delegate of the UITableView object after the UITableView object is created, and points to itself, as shown in:
! [Enter description here] [1]

UITableView Data Source

uitableview object queries the other object itself for the content to be displayed, which is the data source of the UITableView object, which is the object that the DataSource property points to.
tableview:numberofrowsinsecton: and tableview:cellforrowatindexpath: is the two method that must be implemented in a protocol. The UITableView object can obtain the number of rows that should be displayed and the views needed to display each row through these two methods of the data source object.

    • Tableview:numberofrowsinsection:
      Method prototypes

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

This method is a required method in Uitableviewdatasource, which returns an integer value (Nsinteger) that represents the function displayed by the UITableView object.
uitableview objects can display data in segments, and each table segment (section) contains a separate set of rows. Incoming tableview:numberofrowsinsecton: The section in the method is used to specify a table segment.
-TableView: Cellforrowatindexpath:
method prototype:

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

Before you introduce this method, you need to introduce another class: UITableViewCell

UITableViewCell Introduction



![ Enter description Here][2]

The following assumes that we want to display some columns of a object in the table. We need to display the description of an object A through the Textlabel property of the UITableViewCell object. This is the second necessary method to implement the Uitableviewdatasource protocol tableView:cellForRowAtIndexPath: --
the tableView:cellForRowAtIndexPath: tasks that need to be done are to create a UITableViewCell object, get the A object represented by the UITableViewCell object, send a description message to the A object, Assigns the resulting descriptive information to the Textlabel property of the UITableViewCell object, and finally returns the UITableViewCell object.
The tableView:cellForRowAtIndexPath: second parameter passed in is a Nsindexpath object that contains two attribute sections (segments) and row (row). When a UITableView object sends a message to its data source tableView:cellForRowAtIndexPath: , its purpose is to obtain a UITableViewCell object that displays the section of the first and second row rows of data.

Reusing UITableViewCell Objects

iOS device memory is limited, so if a UITableView object is to display a large number of records and the corresponding UITableViewCell object is created for each record, the memory of the iOS device will be exhausted quickly.
To solve this problem, you need to reuse the Uitabelviewcell object. When the user scrolls the Uitbelview object, some UITableViewCell objects are moved out of the window. The UITableView object places the UITableViewCell object that is moved out of the window into the UITableViewCell object pool for reuse. When the UITableView object requires the data source to return a UITableViewCell object, the data source can view the object pool first. If you have an unused Uitabelviewcell object, you can configure the UITableViewCell object with the new data and then return it to the UITableView object to avoid creating a new object.

Summary

When using UITableView, keep in mind that UITableView is a view and is only responsible for display, not data and logical processing. If you want UITableView to appear in multiple table segments, or to perform other complex displays, you should place the judgment logic in the Model section and then pass the judged results into UITableView with the controller.
[1]:./images/1464090777571.jpg "1464090777571.jpg"
[2]:./images/1464093634179.jpg "1464093634179.jpg"

Uitableviewcontroller&uitableview of iOS Learning notes

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.