iOS Development UI Chapter-uitableview Control Usage Summary

Source: Internet
Author: User

First,the use of UITableView steps

The use of UITableView is only a simple three-step process:

1. Tell how many sets of data are in total

Method:-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView;

2. Tell each group how many lines are in total

Method:-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section;

3. Set each group per row (cell)

Method:-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath;

Ii. Description of Use

1. How many sets of data and how many rows are usually related to data, in development data is usually stored in the plist file and needs to be loaded into the project (model) in a certain way.

2. Set each row of each group, say simple point is to set the TableView in each cell.

There are three steps to setting up a cell:

(1) Create a cell (you need to consider performance, recycle the cell, pay attention to how the cache is handled)

(2) Setting data for cell

(3) Returns a cell

There are three ways to set up a cell:

(1) Setup with system-provided Tableviewcell

(2) through Xib custom Tableviewcell, applicable to raised here consistent, such as the group purchase display interface

(3) Through pure code custom Tableviewcell, applicable to gaps, such as performance is not the same, some cells have a property, and some cells do not, such as Weibo display interface

Third, custom Tableviewcell

1. To customize a view by using the Xib file

(1) Create a new Xib file that describes a view's internal

(2) Create a new custom class, the custom class needs to inherit from the system comes with the view, inherits from which class, depends on the xib and the object's class

(3) The type of the new class is best aligned with the Xib file name

(4) wiring the Xib control and the. m file of the custom class

(5) Provides a method of a class to return a created custom iview (masking the process of loading from xib)

(6) Provide a model attribute to allow the outside world to pass model data

(7) Override the setter method of the Model property, where the model data is presented to the corresponding child controls

2. Customizing the cell by way of code

(1) New? A class that inherits from UITableViewCell

(2) Rewrite Initwithstyle:reuseidentifier: Method

Add all the child controls that need to be displayed (you don't need to set the child control's data and frame, and the child controls are added to the Contentview)

One-time property setting for child controls (some properties need to be set only once, such as fonts \ fixed images)

(3) 2 models available

Data model: Storing text data \ Picture data

Frame model: The height of the Frame\cell that holds the data model \ All child controls

(4) Cell has a frame model (do not have a data model directly)

(5) Override the setter method of the Frame model property: Set the child control's display data and frame in this method

(6) The initialization of frame model data has been taken by lazy loading (each cell corresponding frame model data is loaded only once)

Iv. steps to use the agent

(1) Find out who is Who's agent first (delegate)

(2) Define proxy protocol, naming specification for protocol Name: control class name + Delegate

(3) Defining proxy methods

Proxy methods are generally defined as @optional

Proxy method names begin with the control name

The proxy method has at least 1 parameters, passing the control itself out

(4) Set proxy (Delegate) object (for example myview.delegate = xxxx;)

Proxy Object Compliance Protocol

The implementation method of the Proxy object Implementation protocol

(5) At the right time to adjust the proxy method of the proxy object (delegate), notify the agent what's going on

(Do you know if the agent implemented the agent before tuning?)

iOS Development UI Chapter-uitableview Control Usage Summary

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.