社會閱歷淺的人儒拂,當(dāng)冒犯發(fā)生時(shí)蹬碧,會第一時(shí)間追隨原始情緒進(jìn)行反擊,然后這樣的反擊多半沒有深入思考避凝,并缺乏策略,最終的結(jié)果只會得不償失眨补。
成熟的人管削,當(dāng)事情發(fā)生時(shí),他有一個(gè)龐大的數(shù)據(jù)庫為其提供信息撑螺,然后有數(shù)位情緒議員提供不同建議含思,最后大腦快速反應(yīng)以后,選擇對自己最有利的行動甘晤。
為此心理學(xué)家Sell提出了憤怒標(biāo)定理論 ( The Recal-ibrational Theory of Anger)含潘,個(gè)體憤怒的產(chǎn)生源于對方的獲利行為絲毫不在意會對你的權(quán)利造成侵犯。
也就是說线婚,我們憤怒不完全因?yàn)閷Ψ綄ξ覀冊斐蓳p失遏弱,而是因?yàn)閷Ψ骄尤豢梢运烈馇趾ξ覀兊睦娑划a(chǎn)生任何愧疚,甚至得意忘形塞弊。相反漱逸,我們自身為了不打擾別人泪姨,卻一直小心翼翼守住自己的邊界。
而憤怒系統(tǒng)的激活伴隨著個(gè)體兩種策略的出現(xiàn):
策略一:使對方產(chǎn)生損失(如攻擊對方)饰抒;
策略二:撤銷或降低對方可以從自己身上獲得的潛在收益 ( 如在對方需要同他人合作才能順利完成的一項(xiàng)任務(wù)中拒絕與其合作) 肮砾。
成熟的人會優(yōu)先選擇策略二,因?yàn)椴呗砸浑m然直接袋坑,但是會消耗自己大量資源仗处,還會違反社會行為規(guī)范。
選擇策略二不僅能有效減少敵人收益枣宫,而且更加隱蔽婆誓,為你贏得有效打擊敵人所需要的機(jī)會。
@interface UITableView : UIScrollView <NSCoding>
Description
Displays hierarchical lists of information and supports selection and editing of the information.
顯示分層的信息列表镶柱,并且支持信息的選擇和編輯旷档。
A table view displays a list of items in a single column. UITableView is a subclass of UIScrollView, which allows users to scroll through the table, although UITableView allows vertical scrolling only. The cells comprising the individual items of the table are UITableViewCell objects; UITableView uses these objects to draw the visible rows of the table. Cells have content—titles and images—and can have, near the right edge, accessory views. Standard accessory views are disclosure indicators or detail disclosure buttons; the former leads to the next level in a data hierarchy and the latter leads to a detailed view of a selected item. Accessory views can also be framework controls, such as switches and sliders, or can be custom views. Table views can enter an editing mode where users can insert, delete, and reorder rows of the table.
tableView在單列中顯示項(xiàng)目列表。UITableView是UIScrollView的子類歇拆,允許用戶滾動table鞋屈,但是UITableViwe僅允許垂直滾動。table中包含的各個(gè)cell是UITableViewCell對象故觅。UITableView使用這些對象來繪制table的可見cell厂庇。cell的內(nèi)容有titile和image,并且在右邊緣的旁邊可以有一個(gè)accessoryView输吏。標(biāo)準(zhǔn)的accessoryView是disclosureIndicators 或 detailDisclosure 按鈕权旷;前者表示到數(shù)據(jù)層次的下一級,后者表示到所選到詳細(xì)視圖贯溅。accessoryView也可以是框架控件拄氯,例如switch和slider或自定義view。tableView能進(jìn)入編輯模式它浅,用戶可以對cell進(jìn)行插入刪除和重新排序的操作译柏。
A table view is made up of zero or more sections, each with its own rows. Sections are identified by their index number within the table view, and rows are identified by their index number within a section. Any section can optionally be preceded by a section header, and optionally be followed by a section footer.
tableVeiw由0個(gè)或多個(gè)section組成。每一個(gè)section都有自己的row姐霍。tableView中的section使用索引號來標(biāo)識鄙麦。section中的cell由sectoin的索引號來標(biāo)識。任何section都可以選擇在頭部設(shè)置sectionHeader镊折,和在尾部設(shè)置sectionFooter胯府。
Table views can have one of two styles, UITableViewStylePlain and UITableViewStyleGrouped. When you create a UITableView instance you must specify a table style, and this style cannot be changed. In the plain style, section headers and footers float above the content if the part of a complete section is visible. A table view can have an index that appears as a bar on the right hand side of the table (for example, "A" through "Z"). You can touch a particular label to jump to the target section. The grouped style of table view provides a default background color and a default background view for all cells. The background view provides a visual grouping for all cells in a particular section. For example, one group could be a person's name and title, another group for phone numbers that the person uses, and another group for email accounts and so on. See the Settings application for examples of grouped tables. Table views in the grouped style cannot have an index.
tableView可以有 UITableViewStylePlain 和 UITableViewStyleGrouped兩種樣式中的一種。當(dāng)你創(chuàng)建一個(gè)tableView實(shí)例的時(shí)候恨胚,你必須指定table的樣式骂因,并且在創(chuàng)建之后這個(gè)樣式不能修改。在Plian樣式中赃泡,如果能看見完整section的一部分侣签, 則section的header和footer會懸浮于內(nèi)容上方塘装。tableView可以有一個(gè)索引以欄的形式出現(xiàn)在table的右手邊(例如“A“~”Z”)。你可以觸摸特定定標(biāo)簽跳到目標(biāo)section影所。一個(gè)Group樣式的table為所有的cell提供默認(rèn)的背景顏色和背景視圖蹦肴。背景視圖為特定section中的所有cell提供可視分組。例如一組是一個(gè)人的名字和標(biāo)題猴娩,另一組是這個(gè)人使用的一組電話號碼阴幌,另一個(gè)組是email用戶等等。有關(guān)Group樣式的table示例卷中,你可以參閱手機(jī)中的設(shè)置程序矛双。Group樣式的tableview不能有索引欄。
Many methods of UITableView take NSIndexPath objects as parameters and return values. UITableView declares a category on NSIndexPath that enables you to get the represented row index (row property) and section index (section property), and to construct an index path from a given row index and section index (indexPathForRow:inSection: method). Especially in table views with multiple sections, you must evaluate the section index before identifying a row by its index number.
許多UITableView方法以NSIndexPath對象作為參數(shù)蟆豫,并且返回值议忽。UITableView在NSIndexPath上聲明一個(gè)分類,它使你可以獲取當(dāng)前row索引(row 屬性)和section索引(seciton 屬性)十减,并且從給定的row索引和seciton索引構(gòu)造indexPath(indexPathForRow:inSection: method)栈幸。特別是在具有多個(gè)section的table中,你必須首先評估section索引帮辟,然后再通過其索引標(biāo)識row速址。
A UITableView object must have an object that acts as a data source and an object that acts as a delegate; typically these objects are either the application delegate or, more frequently, a custom UITableViewController object. The data source must adopt the UITableViewDataSource protocol and the delegate must adopt the UITableViewDelegate protocol. The data source provides information that UITableView needs to construct tables and manages the data model when rows of a table are inserted, deleted, or reordered. The delegate manages table row configuration and selection, row reordering, highlighting, accessory views, and editing operations.
一個(gè)UITableView對象必須有一個(gè)充當(dāng)數(shù)據(jù)源的對象和充當(dāng)委托的對象;通常這些對象是應(yīng)用程序委托或者是一個(gè)自定義UITableViewController對象由驹。數(shù)據(jù)源必須采用UITableViewDelegate協(xié)議芍锚,委托必須采用UITableViewDelegate協(xié)議。數(shù)據(jù)源提供在table的cell插入蔓榄,刪除并炮,重新排序時(shí),UITableView需要構(gòu)造table和管理數(shù)據(jù)模型的信息甥郑。委托管理table的cell的配置和選擇渣触,cell的重新排序,顯示高亮的附件視圖和編輯操作壹若。
When sent a setEditing:animated: message (with a first parameter of YES), the table view enters into editing mode where it shows the editing or reordering controls of each visible row, depending on the editingStyle of each associated UITableViewCell. Clicking on the insertion or deletion control causes the data source to receive a tableView:commitEditingStyle:forRowAtIndexPath: message. You commit a deletion or insertion by calling deleteRowsAtIndexPaths:withRowAnimation: or insertRowsAtIndexPaths:withRowAnimation:, as appropriate. Also in editing mode, if a table-view cell has its showsReorderControl property set to YES, the data source receives a tableView:moveRowAtIndexPath:toIndexPath: message. The data source can selectively remove the reordering control for cells by implementing tableView:canMoveRowAtIndexPath:.
當(dāng)發(fā)送setEditing:animated:消息(第一個(gè)參數(shù)為YES)時(shí),tableView進(jìn)入編輯模式皂冰,根據(jù)各個(gè)關(guān)聯(lián)的UITableViewCell的editingStyle店展,顯示每個(gè)可見cell的編輯或重新排序控件。點(diǎn)擊插入或刪除控件將導(dǎo)致數(shù)據(jù)源接收到tableView:commitEditingStyle:forRowAtIndexPath: 消息秃流。通過調(diào)用deleteRowsAtIndexPaths:withRowAnimation: 或 insertRowsAtIndexPaths:withRowAnimation:方法赂蕴, 你可以提交刪除和插入的操作。
同樣在編輯模式下舶胀,如果tableViewCell設(shè)置了showsReorderControl為YES概说,則數(shù)據(jù)源會收到tableView:moveRowAtIndexPath:toIndexPath: 消息碧注。數(shù)據(jù)源通過實(shí)現(xiàn)tableView:canMoveRowAtIndexPath:,可以有選擇地刪除cell的重新排序控件糖赔。
UITableView caches table-view cells for visible rows. You can create custom UITableViewCell objects with content or behavioral characteristics that are different than the default cells; A Closer Look at Table View Cells explains how.
UITableView overrides the layoutSubviews method of UIView so that it calls reloadData only when you create a new instance of UITableView or when you assign a new data source. Reloading the table view clears current state, including the current selection. However, if you explicitly call reloadData, it clears this state and any subsequent direct or indirect call to layoutSubviews does not trigger a reload.
UITalbeView為可見row緩存talbViewCell萍丐。你可以使用content或行為特性不同于默認(rèn)的cell來創(chuàng)建自定義UITableView對象,你可以通過仔細(xì)觀察tableViewCell來解析為何這樣放典。UITalbeView覆蓋UIView的layoutSubviews方法逝变,以便它僅在你創(chuàng)建一個(gè)新的實(shí)例或分配新的數(shù)據(jù)源時(shí),調(diào)用reloadData方法奋构。重新加載tableView會清除當(dāng)前狀態(tài)壳影,包括當(dāng)前選擇狀態(tài)。但是弥臼,如果你顯式調(diào)用reloadData宴咧,則會清除這個(gè)狀態(tài),并且任何后續(xù)直接或間接調(diào)用layoutSubviews径缅,都不會觸發(fā)reload掺栅。
For information about basic view behaviors, see View Programming Guide for iOS.
有關(guān)基礎(chǔ)view的行為信息,請參閱iOS視圖編程指南芥驳。
-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
初始化并返回具有給定frame和style的tableView對象柿冲。你必須指定tableView的style,并且在此之后不能修改style兆旬。如果你使用initWithFrame:初始化tableView假抄,則默認(rèn)使用UITableViewStylePlain樣式。tableView的frame隨著cell的添加和刪除而改變丽猬。
Description
Initializes and returns a table view object having the given frame and style.
You must specify the style of a table view when you create it and you cannot thereafter modify the style. If you initialize the table view with the UIView method initWithFrame:, the UITableViewStylePlain style is used as a default.
Parameters
frame
A rectangle specifying the initial location and size of the table view in its superview’s coordinates. The frame of the table view changes as table cells are added and deleted.
style
A constant that specifies the style of the table view. See UITableViewStyle for descriptions of valid constants.
Returns
Returns an initialized UITableView object.
Availability iOS (2.0 and later), tvOS (9.0 and later)
UITableViewStyleGrouped
在tableView中宿饱,每個(gè)section是一個(gè)呈現(xiàn)獨(dú)特內(nèi)容的行組,section的頁眉頁腳不會浮動
Description
A table view whose sections present distinct groups of rows. The section headers and footers do not float.
Availability iOS (2.0 and later), tvOS (9.0 and later)
UITableViewStylePlain
普通tableView脚祟,任何section的頁眉頁腳顯示如同內(nèi)聯(lián)分割符谬以,并在滾動tableView時(shí)浮動。
Description
A plain table view. Any section headers or footers are displayed as inline separators and float when the table view is scrolled.
Availability iOS (2.0 and later), tvOS (9.0 and later)
@property(nonatomic) CGFloat sectionHeaderHeight;
tableView中section的Header的高度由桌,此值為非負(fù)值为黎,在代理方法tableView:heightForHeaderInSection: 沒有實(shí)現(xiàn)的時(shí)候才起作用,如果沒有設(shè)置該值行您,則返回默認(rèn)值铭乾。
Description
The height of section headers in the table view.
This nonnegative value is used only if the delegate doesn’t implement the tableView:heightForHeaderInSection: method.
Availability iOS (2.0 and later), tvOS (9.0 and later)
/ / will return the default value if unset
@property(nonatomic) CGFloat sectionFooterHeight;
tableView中section的Footer的高度,此值為非負(fù)值娃循,在tableview的樣式為UITableViewStyleGroup炕檩,并且代理方法tableView:heightForFooterInSection: 沒有實(shí)現(xiàn)的時(shí)候才起作用,如果沒有設(shè)置該值捌斧,則返回默認(rèn)值笛质。
Description
The height of section footers in the table view.
This nonnegative value is used only in section group tables and only if the delegate doesn't implement the tableView:heightForFooterInSection: method.
Availability iOS (2.0 and later), tvOS (9.0 and later)
/ / will return the default value if unset
@property(nonatomic, strong) UIView *tableHeaderView;
返回顯示在tableView上方的附件視圖泉沾,默認(rèn)值為nil,tableHeaderView不同于secitonHeaderView
Description
Returns an accessory view that is displayed above the table.
The default value is nil. The table header view is different from a section header.
Availability iOS (2.0 and later), tvOS (9.0 and later)
@property(nonatomic, strong) UIView *tableFooterView;
返回顯示在tableView下方的附件視圖妇押,默認(rèn)值為nil跷究,tableFooterView不同于secitonFooterView
Description
Returns an accessory view that is displayed below the table.
The default value is nil. The table footer view is different from a section footer.
Availability iOS (2.0 and later), tvOS (9.0 and later)
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
代理方法,返回一個(gè)非負(fù)值舆吮,可以指定不同section的Header的高度揭朝。
Description
Asks the delegate for the height to use for the header of a particular section.
This method allows the delegate to specify section headers with varying heights.
Parameters
tableView
The table-view object requesting this information.
section
An index number identifying a section of tableView .
Returns
A nonnegative floating-point value that specifies the height (in points) of the header for section.
Availability iOS (2.0 and later), tvOS (9.0 and later)
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
代理方法:返回一個(gè)非負(fù)值,可以指定不同section的Footer的高度色冀,如果tableView的樣式為UITableViewStylePlain潭袱,則不會調(diào)用此方法。
Description
Asks the delegate for the height to use for the footer of a particular section.
This method allows the delegate to specify section footers with varying heights. The table view does not call this method if it was created in a plain style (UITableViewStylePlain).
Parameters
tableView
The table-view object requesting this information.
section
An index number identifying a section of tableView .
Returns
A nonnegative floating-point value that specifies the height (in points) of the footer for section.
Availability iOS (2.0 and later), tvOS (9.0 and later)
tableView: viewForHeaderInSection:
tableView: viewForFooterInSection:
返回section的Header和footer锋恬,將會被調(diào)整到默認(rèn)或指定的高度屯换。 當(dāng)你同時(shí)實(shí)現(xiàn)了該方法和標(biāo)題的方法,則該方法優(yōu)于標(biāo)題方法
custom view for header. will be adjusted to default or specified header height
custom view for footer. will be adjusted to default or specified footer height
Section header & footer information. Views are preferred over title should you decide to provide both
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
調(diào)用代理方法:顯示指定section的header与学,返回的對象可以是UILabel或UIImageView彤悔,也可以是自定義視圖。此方法只有在實(shí)現(xiàn)了tableView:heightForHeaderInSection: 時(shí)才起作用索守。
Description
Asks the delegate for a view object to display in the header of the specified section of the table view.
The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForHeaderInSection: is also implemented.
Parameters
tableView
The table-view object asking for the view object.
section
An index number identifying a section of tableView .
Returns
A view object to be displayed in the header of section .
Availability iOS (2.0 and later), tvOS (9.0 and later)
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
調(diào)用代理方法:顯示指定section的footer晕窑,返回的對象可以是UILabel或UIImageView,也可以是自定義視圖卵佛。此方法只有在實(shí)現(xiàn)了 tableView:heightForFooterInSection: 時(shí)才起作用杨赤。
Description
Asks the delegate for a view object to display in the footer of the specified section of the table view.
The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForFooterInSection: is also implemented.
Parameters
tableView
The table-view object asking for the view object.
section
An index number identifying a section of tableView .
Returns
A view object to be displayed in the footer of section .
Availability iOS (2.0 and later), tvOS (9.0 and later)