
社會閱歷淺的人,當(dāng)冒犯發(fā)生時,會第一時間追隨原始情緒進(jìn)行反擊,然后這樣的反擊多半沒有深入思考,并缺乏策略,最終的結(jié)果只會得不償失。
成熟的人,當(dāng)事情發(fā)生時,他有一個龐大的數(shù)據(jù)庫為其提供信息,然后有數(shù)位情緒議員提供不同建議,最后大腦快速反應(yīng)以后,選擇對自己最有利的行動。
為此心理學(xué)家Sell提出了憤怒標(biāo)定理論 ( The Recal-ibrational Theory of Anger),個體憤怒的產(chǎn)生源于對方的獲利行為絲毫不在意會對你的權(quán)利造成侵犯。
也就是說,我們憤怒不完全因為對方對我們造成損失,而是因為對方居然可以肆意侵害我們的利益而不產(chǎn)生任何愧疚,甚至得意忘形。相反,我們自身為了不打擾別人,卻一直小心翼翼守住自己的邊界。
而憤怒系統(tǒng)的激活伴隨著個體兩種策略的出現(xiàn):
策略一:使對方產(chǎn)生損失(如攻擊對方);
策略二:撤銷或降低對方可以從自己身上獲得的潛在收益 ( 如在對方需要同他人合作才能順利完成的一項任務(wù)中拒絕與其合作) 。
成熟的人會優(yōu)先選擇策略二,因為策略一雖然直接,但是會消耗自己大量資源,還會違反社會行為規(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在單列中顯示項目列表。UITableView是UIScrollView的子類,允許用戶滾動table,但是UITableViwe僅允許垂直滾動。table中包含的各個cell是UITableViewCell對象。UITableView使用這些對象來繪制table的可見cell。cell的內(nèi)容有titile和image,并且在右邊緣的旁邊可以有一個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個或多個section組成。每一個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)建一個tableView實例的時候,你必須指定table的樣式,并且在創(chuàng)建之后這個樣式不能修改。在Plian樣式中,如果能看見完整section的一部分, 則section的header和footer會懸浮于內(nèi)容上方。tableView可以有一個索引以欄的形式出現(xiàn)在table的右手邊(例如“A“~”Z”)。你可以觸摸特定定標(biāo)簽跳到目標(biāo)section。一個Group樣式的table為所有的cell提供默認(rèn)的背景顏色和背景視圖。背景視圖為特定section中的所有cell提供可視分組。例如一組是一個人的名字和標(biāo)題,另一組是這個人使用的一組電話號碼,另一個組是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上聲明一個分類,它使你可以獲取當(dāng)前row索引(row 屬性)和section索引(seciton 屬性),并且從給定的row索引和seciton索引構(gòu)造indexPath(indexPathForRow:inSection: method)。特別是在具有多個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.
一個UITableView對象必須有一個充當(dāng)數(shù)據(jù)源的對象和充當(dāng)委托的對象;通常這些對象是應(yīng)用程序委托或者是一個自定義UITableViewController對象。數(shù)據(jù)源必須采用UITableViewDelegate協(xié)議,委托必須采用UITableViewDelegate協(xié)議。數(shù)據(jù)源提供在table的cell插入,刪除,重新排序時,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:消息(第一個參數(shù)為YES)時,tableView進(jìn)入編輯模式,根據(jù)各個關(guān)聯(lián)的UITableViewCell的editingStyle,顯示每個可見cell的編輯或重新排序控件。點擊插入或刪除控件將導(dǎo)致數(shù)據(jù)源接收到tableView:commitEditingStyle:forRowAtIndexPath: 消息。通過調(diào)用deleteRowsAtIndexPaths:withRowAnimation: 或 insertRowsAtIndexPaths:withRowAnimation:方法, 你可以提交刪除和插入的操作。
同樣在編輯模式下,如果tableViewCell設(shè)置了showsReorderControl為YES,則數(shù)據(jù)源會收到tableView:moveRowAtIndexPath:toIndexPath: 消息。數(shù)據(jù)源通過實現(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)建一個新的實例或分配新的數(shù)據(jù)源時,調(diào)用reloadData方法。重新加載tableView會清除當(dāng)前狀態(tài),包括當(dāng)前選擇狀態(tài)。但是,如果你顯式調(diào)用reloadData,則會清除這個狀態(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中,每個section是一個呈現(xiàn)獨特內(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時浮動。
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: 沒有實現(xiàn)的時候才起作用,如果沒有設(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: 沒有實現(xiàn)的時候才起作用,如果沒有設(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;
代理方法,返回一個非負(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;
代理方法:返回一個非負(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)你同時實現(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,也可以是自定義視圖。此方法只有在實現(xiàn)了tableView:heightForHeaderInSection: 時才起作用。
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,也可以是自定義視圖。此方法只有在實現(xiàn)了 tableView:heightForFooterInSection: 時才起作用。
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)