UITableView的使用——常用API翻译

loading.png

社会阅历浅的人,当冒犯发生时,会第一时间追随原始情绪进行反击,然后这样的反击多半没有深入思考,并缺乏策略,最终的结果只会得不偿失。

成熟的人,当事情发生时,他有一个庞大的数据库为其提供信息,然后有数位情绪议员提供不同建议,最后大脑快速反应以后,选择对自己最有利的行动。

为此心理学家Sell提出了愤怒标定理论 ( The Recal-ibrational Theory of Anger),个体愤怒的产生源于对方的获利行为丝毫不在意会对你的权利造成侵犯。

也就是说,我们愤怒不完全因为对方对我们造成损失,而是因为对方居然可以肆意侵害我们的利益而不产生任何愧疚,甚至得意忘形。相反,我们自身为了不打扰别人,却一直小心翼翼守住自己的边界。

而愤怒系统的激活伴随着个体两种策略的出现:

策略一:使对方产生损失(如攻击对方);

策略二:撤销或降低对方可以从自己身上获得的潜在收益 ( 如在对方需要同他人合作才能顺利完成的一项任务中拒绝与其合作) 。

成熟的人会优先选择策略二,因为策略一虽然直接,但是会消耗自己大量资源,还会违反社会行为规范。

选择策略二不仅能有效减少敌人收益,而且更加隐蔽,为你赢得有效打击敌人所需要的机会。


@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的内容有titile和image,并且在右边缘的旁边可以有一个accessoryView。标准的accessoryView是disclosureIndicators 或 detailDisclosure 按钮;前者表示到数据层次的下一级,后者表示到所选到详细视图。accessoryView也可以是框架控件,例如switch和slider或自定义view。tableView能进入编辑模式,用户可以对cell进行插入删除和重新排序的操作。

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使用索引号来标识。section中的cell由sectoin的索引号来标识。任何section都可以选择在头部设置sectionHeader,和在尾部设置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两种样式中的一种。当你创建一个tableView实例的时候,你必须指定table的样式,并且在创建之后这个样式不能修改。在Plian样式中,如果能看见完整section的一部分, 则section的header和footer会悬浮于内容上方。tableView可以有一个索引以栏的形式出现在table的右手边(例如“A“~”Z”)。你可以触摸特定定标签跳到目标section。一个Group样式的table为所有的cell提供默认的背景颜色和背景视图。背景视图为特定section中的所有cell提供可视分组。例如一组是一个人的名字和标题,另一组是这个人使用的一组电话号码,另一个组是email用户等等。有关Group样式的table示例,你可以参阅手机中的设置程序。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对象作为参数,并且返回值。UITableView在NSIndexPath上声明一个分类,它使你可以获取当前row索引(row 属性)和section索引(seciton 属性),并且从给定的row索引和seciton索引构造indexPath(indexPathForRow:inSection: method)。特别是在具有多个section的table中,你必须首先评估section索引,然后再通过其索引标识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对象必须有一个充当数据源的对象和充当委托的对象;通常这些对象是应用程序委托或者是一个自定义UITableViewController对象。数据源必须采用UITableViewDelegate协议,委托必须采用UITableViewDelegate协议。数据源提供在table的cell插入,删除,重新排序时,UITableView需要构造table和管理数据模型的信息。委托管理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:.
当发送setEditing:animated:消息(第一个参数为YES)时,tableView进入编辑模式,根据各个关联的UITableViewCell的editingStyle,显示每个可见cell的编辑或重新排序控件。点击插入或删除控件将导致数据源接收到tableView:commitEditingStyle:forRowAtIndexPath: 消息。通过调用deleteRowsAtIndexPaths:withRowAnimation: 或 insertRowsAtIndexPaths:withRowAnimation:方法, 你可以提交删除和插入的操作。
同样在编辑模式下,如果tableViewCell设置了showsReorderControl为YES,则数据源会收到tableView:moveRowAtIndexPath:toIndexPath: 消息。数据源通过实现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或行为特性不同于默认的cell来创建自定义UITableView对象,你可以通过仔细观察tableViewCell来解析为何这样。UITalbeView覆盖UIView的layoutSubviews方法,以便它仅在你创建一个新的实例或分配新的数据源时,调用reloadData方法。重新加载tableView会清除当前状态,包括当前选择状态。但是,如果你显式调用reloadData,则会清除这个状态,并且任何后续直接或间接调用layoutSubviews,都不会触发reload。

For information about basic view behaviors, see View Programming Guide for iOS.
有关基础view的行为信息,请参阅iOS视图编程指南。

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
初始化并返回具有给定frame和style的tableView对象。你必须指定tableView的style,并且在此之后不能修改style。如果你使用initWithFrame:初始化tableView,则默认使用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是一个呈现独特内容的行组,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的页眉页脚显示如同内联分割符,并在滚动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的高度,此值为非负值,在代理方法tableView:heightForHeaderInSection: 没有实现的时候才起作用,如果没有设置该值,则返回默认值。

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的高度,此值为非负值,在tableview的样式为UITableViewStyleGroup,并且代理方法tableView:heightForFooterInSection: 没有实现的时候才起作用,如果没有设置该值,则返回默认值。

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上方的附件视图,默认值为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下方的附件视图,默认值为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;
代理方法,返回一个非负值,可以指定不同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;
代理方法:返回一个非负值,可以指定不同section的Footer的高度,如果tableView的样式为UITableViewStylePlain,则不会调用此方法。

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,将会被调整到默认或指定的高度。 当你同时实现了该方法和标题的方法,则该方法优于标题方法

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;
调用代理方法:显示指定section的header,返回的对象可以是UILabel或UIImageView,也可以是自定义视图。此方法只有在实现了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;
调用代理方法:显示指定section的footer,返回的对象可以是UILabel或UIImageView,也可以是自定义视图。此方法只有在实现了 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)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,108评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,699评论 1 296
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,812评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,236评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,583评论 3 288
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,739评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,957评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,704评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,447评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,643评论 2 249
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,133评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,486评论 3 256
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,151评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,108评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,889评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,782评论 2 277
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,681评论 2 272

推荐阅读更多精彩内容