UITableView的兩個協(xié)議

UITableViewDataSource:

public
 protocol UITableViewDataSource : NSObjectProtocol {

public
 
func tableView(tableView: UITableView, **numberOfRowsInSection** section: Int) -> Int

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

public
 func tableView(tableView: UITableView, **cellForRowAtIndexPath** indexPath: NSIndexPath) -> UITableViewCell

optional 
public
 func numberOfSectionsInTableView(tableView: UITableView) -> Int 

// Default is 1 if not implemented

optional 
public
 func tableView(tableView: UITableView, **titleForHeaderInSection** section: Int) -> String? 

// fixed font style. use custom view (UILabel) if you want something different

optional 
public
 func tableView(tableView: UITableView, **titleForFooterInSection** section: Int) -> String?

// Editing

// Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable.

optional 
public
 func tableView(tableView: UITableView, **canEditRowAtIndexPath** indexPath: NSIndexPath) -> Bool

// Moving/reordering

// Allows the reorder accessory view to optionally be shown for a particular row. By default, the reorder control will be shown only if the datasource implements -tableView:moveRowAtIndexPath:toIndexPath:

optional 
public
 func tableView(tableView: UITableView, **canMoveRowAtIndexPath** indexPath: NSIndexPath) -> Bool

// Index

optional 
public
 func **sectionIndexTitlesForTableView**(tableView: UITableView) -> [String]? 

 // return list of section titles to display in section index view (e.g. "ABCD...Z#")

optional 
public
 func tableView(tableView: UITableView, **sectionForSectionIndexTitle** title: String, atIndex index: Int) -> Int 

// tell table which section corresponds to section title/index (e.g. "B",1))

// Data manipulation - insert and delete support

// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change

// Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead

optional 
public
 func tableView(tableView: UITableView, **commitEditingStyle** editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)

// Data manipulation - reorder / moving support

optional 
public
 func tableView(tableView: UITableView, **moveRowAtIndexPath** sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)

}

UITableViewDelegate:

public
 protocol UITableViewDelegate : NSObjectProtocol, UIScrollViewDelegate {

// Display customization

@available(iOS 2.0, *)

optional 
public
 func tableView(tableView: UITableView, **willDisplayCell** cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **willDisplayHeaderView** view: UIView, forSection section: Int)

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **willDisplayFooterView** view: UIView, forSection section: Int)

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **didEndDisplayingCell** cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **didEndDisplayingHeaderView** view: UIView, forSection section: Int)

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **didEndDisplayingFooterView** view: UIView, forSection section: Int)

// Variable height support

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **heightForRowAtIndexPath **indexPath: NSIndexPath) -> CGFloat

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **heightForHeaderInSection **section: Int) -> CGFloat

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **heightForFooterInSection **section: Int) -> CGFloat

// Use the estimatedHeight methods to quickly calcuate guessed values which will allow for fast load times of the table.

// If these methods are implemented, the above -tableView:heightForXXX calls will be deferred until views are ready to be displayed, so more expensive logic can be placed there.

@available(iOS 7.0, *)
optional 
public
 func tableView(tableView: UITableView, **estimatedHeightForRowAtIndexPath** indexPath: NSIndexPath) -> CGFloat

@available(iOS 7.0, *)
optional 
public
 func tableView(tableView: UITableView, 
**estimatedHeightForHeaderInSection **
section: Int) -> CGFloat

@available(iOS 7.0, *)
optional 
public
 func tableView(tableView: UITableView, **estimatedHeightForFooterInSection **section: Int) -> CGFloat

// Section header & footer information. Views are preferred over title should you decide to provide both

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **viewForHeaderInSection **section: Int) -> UIView? 
// custom view for header. will be adjusted to default or specified header height

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **viewForFooterInSection **section: Int) -> UIView? 
// custom view for footer. will be adjusted to default or specified footer height

// Accessories (disclosures). 

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **accessoryButtonTappedForRowWithIndexPath **indexPath: NSIndexPath)

// Selection

// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row. 

// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **shouldHighlightRowAtIndexPath **indexPath: NSIndexPath) -> Bool

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, **didHighlightRowAtIndexPath **indexPath: NSIndexPath)

@available(iOS 6.0, *)
optional 
public
 func tableView(tableView: UITableView, 
**didUnhighlightRowAtIndexPath **
indexPath: NSIndexPath)

// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **willSelectRowAtIndexPath **indexPath: NSIndexPath) -> NSIndexPath?

@available(iOS 3.0, *)
optional 
public
 func tableView(tableView: UITableView, **willDeselectRowAtIndexPath **indexPath: NSIndexPath) -> NSIndexPath?

// Called after the user changes the selection.

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **didSelectRowAtIndexPath **indexPath: NSIndexPath)

@available(iOS 3.0, *)
optional 
public
 func tableView(tableView: UITableView, **didDeselectRowAtIndexPath **indexPath: NSIndexPath)

// Editing

// Allows customization of the editingStyle for a particular cell located at 'indexPath'. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **editingStyleForRowAtIndexPath **indexPath: NSIndexPath) -> UITableViewCellEditingStyle

@available(iOS 3.0, *)
optional 
public
 func tableView(tableView: UITableView, 
**titleForDeleteConfirmationButtonForRowAtIndexPath **
indexPath: NSIndexPath) -> String?

@available(iOS 8.0, *)
optional 
public
 func tableView(tableView: UITableView, **editActionsForRowAtIndexPath **indexPath: NSIndexPath) -> [UITableViewRowAction]? 
// supercedes -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: if return value is non-nil

// Controls whether the background is indented while editing.  If not implemented, the default is YES.  This is unrelated to the indentation level below.  This method only applies to grouped style table views.

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **shouldIndentWhileEditingRowAtIndexPath **indexPath: NSIndexPath) -> Bool

// The willBegin/didEnd methods are called whenever the 'editing' property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **willBeginEditingRowAtIndexPath **indexPath: NSIndexPath)

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **didEndEditingRowAtIndexPath **indexPath: NSIndexPath)

// Moving/reordering

// Allows customization of the target row for a particular row as it is being moved/reordered

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **targetIndexPathForMoveFromRowAtIndexPath **sourceIndexPath: NSIndexPath, toProposedIndexPath proposedDestinationIndexPath: NSIndexPath) -> NSIndexPath

// Indentation

@available(iOS 2.0, *)
optional 
public
 func tableView(tableView: UITableView, **indentationLevelForRowAtIndexPath **indexPath: NSIndexPath) -> Int 
// return 'depth' of row for hierarchies
// Copy/Paste.  All three methods must be implemented by the delegate.

@available(iOS 5.0, *)
optional 
public
 func tableView(tableView: UITableView, **shouldShowMenuForRowAtIndexPath **indexPath: NSIndexPath) -> Bool

@available(iOS 5.0, *)
optional 
public
 func tableView(tableView: UITableView, canPerformAction action: Selector, **forRowAtIndexPath **indexPath: NSIndexPath, withSender sender: AnyObject?) -> Bool

@available(iOS 5.0, *)
optional 
public
 func tableView(tableView: UITableView, performAction action: Selector, **forRowAtIndexPath **indexPath: NSIndexPath, withSender sender: AnyObject?)

// Focus

@available(iOS 9.0, *)
optional 
public
 func tableView(tableView: UITableView, **canFocusRowAtIndexPath **indexPath: NSIndexPath) -> Bool

@available(iOS 9.0, *)
optional 
public
 func tableView(tableView: UITableView, **shouldUpdateFocusInContext **context: UITableViewFocusUpdateContext) -> Bool

@available(iOS 9.0, *)
optional 
public
 func tableView(tableView: UITableView, **didUpdateFocusInContext **context: UITableViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)

@available(iOS 9.0, *)
optional 
public
 func **indexPathForPreferredFocusedViewInTableView**(tableView: UITableView) -> NSIndexPath?
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市各墨,隨后出現(xiàn)的幾起案子温技,更是在濱河造成了極大的恐慌牌借,老刑警劉巖吼野,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件聘鳞,死亡現(xiàn)場離奇詭異葛峻,居然都是意外死亡锹雏,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進(jìn)店門术奖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來逼侦,“玉大人,你說我怎么就攤上這事腰耙¢欢” “怎么了?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵挺庞,是天一觀的道長晰赞。 經(jīng)常有香客問我,道長选侨,這世上最難降的妖魔是什么掖鱼? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮援制,結(jié)果婚禮上戏挡,老公的妹妹穿的比我還像新娘。我一直安慰自己晨仑,他們只是感情好褐墅,可當(dāng)我...
    茶點故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著洪己,像睡著了一般妥凳。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上答捕,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天逝钥,我揣著相機(jī)與錄音,去河邊找鬼拱镐。 笑死艘款,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的沃琅。 我是一名探鬼主播哗咆,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼阵难!你這毒婦竟也來了岳枷?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤呜叫,失蹤者是張志新(化名)和其女友劉穎空繁,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體朱庆,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡盛泡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了娱颊。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片傲诵。...
    茶點故事閱讀 39,703評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖箱硕,靈堂內(nèi)的尸體忽然破棺而出拴竹,到底是詐尸還是另有隱情,我是刑警寧澤剧罩,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布栓拜,位于F島的核電站,受9級特大地震影響惠昔,放射性物質(zhì)發(fā)生泄漏幕与。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一镇防、第九天 我趴在偏房一處隱蔽的房頂上張望啦鸣。 院中可真熱鬧,春花似錦来氧、人聲如沸诫给。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蝙搔。三九已至,卻和暖如春考传,著一層夾襖步出監(jiān)牢的瞬間吃型,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工僚楞, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留勤晚,地道東北人。 一個月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓泉褐,卻偏偏與公主長得像赐写,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子膜赃,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,601評論 2 353

推薦閱讀更多精彩內(nèi)容