[通俗易懂]理解“委托”

委托的意义在于实现多态;在于让对象可以在程序运行时知足外界对其的改变。html

(1)一个对象属性、动做,若是在编译时就能肯定,能够在这个对象的类里面来实现。ios

(2)一个对象的属性、动做,若是在运行时才能肯定,则只能经过这个对象的委托来实现。api

换句话说:类,知足编译时对对象的设置和要求。委托,用于知足运行时对对象的设置和要求。app

举个例子:UITableView 的一个实例对象 tableView。ui

当咱们在使用tableView时,咱们在编译的时候就能肯定下来这个表格的分割线颜色(separatorColor )、分割线风格(separatorStyle )、背景图片(backgroundView)等。还有一些,咱们在编译的时候就能够执行的方法。如:spa

固然,那些只有在运行时才能肯定的方面,咱们只能在类的委托中实现(由于在编译的时候,咱们没法肯定其状态是怎样的)。以下面这些:设计

以上,就是对委托的所有理解。若是看着还不过瘾,咱们能够经过以下篇幅,窥视一下苹果公司是如何设计tableview的。rest

苹果公司设计tableview在编译时就要肯定的方面包括:==UITableView Class Referencecode

 

Tasks

Initializing a UITableView Object

Configuring a Table View

Creating Table View Cells

Accessing Header and Footer Views

Accessing Cells and Sections

Estimating Element Heights

Scrolling the Table View

Managing Selections

Inserting, Deleting, and Moving Rows and Sections

Managing the Editing of Table Cells

Reloading the Table View

Accessing Drawing Areas of the Table View

Managing the Delegate and the Data Source

Configuring the Table Index

 

苹果公司设计tableview在运行时才能肯定的方面包括:==UITableViewDelegate Protocol Referenceorm

 

Tasks

Configuring Rows for the Table View

Managing Accessory Views

Managing Selections

Modifying the Header and Footer of Sections

Editing Table Rows

Reordering Table Rows

Tracking the Removal of Views

Copying and Pasting Row Content

Managing Table View Highlighting

相关文章
相关标签/搜索