亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這個section表示的又是什么呢?它的方法原型如下

這個section表示的又是什么呢?它的方法原型如下

米琪卡哇伊 2023-04-08 17:13:47
在controller中delegate了UITableViewDataSource以后,是必須實現這個方法以展示UITableView的。- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath能否結合例子具體解釋下NSIndexPath的含義,另外與它想對應的還有一個必須實現的方法- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
查看完整描述

2 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

1、NSIndexPath主要包含(NSUInteger)section(NSUInteger)row,每個row必然是屬于一個section的,否則這個row沒有意義,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section里面就是表明各section有多少row。
2、打開Contacts,里面的那些A、B、C...這樣的標題就屬于section header,header + rows + footer就構成了一個完整的section. 可以通過- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;進行定制header,footer類似

查看完整回答
反對 回復 2023-04-11
?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

先解釋一下TableView的布局,一個TableView的內容兩級,Section和Section中的Row,每個Row對應的視圖成為TableViewCell。拿 設置.app 舉例,如下圖:

http://img1.sycdn.imooc.com//6434d40700018e5206400932.jpg

圖中有兩個Section
Section 0 中有6個Row -- 飛行模式~運營商
Section 1 中能看到3個Row -- 聲音~桌面

再說問題里的兩個方法。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

這個方法返回的就是某個cell,可以自定義各種樣式渲染,也可以用幾種默認樣式去渲染。
indexPath標示的是你要渲染的這個cell的位置,indexPath對象里有兩個屬性,section和row,顧名思義,可以定位某個cell。
注意:這個方法會在某個cell出現在屏幕中的時候被調用,而且是沒出現一次就被調用一次。因為一個cell對象在屏幕可見區域消失的時候被回收,給其他出現在可見區域的cell復用。所以,在這個方法里渲染某個cell的時候,最好用個for循環或者什么的把cell清理干凈。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

這個方法,是在TableView生成的時候被調用(或者對tableView對象調用reloadData時),返回某個section中的row(cell)數量。
例如,在 設置.app 的界面里,應該是

switch (seciton) {    0 :        return 6;    1 :        return 3;
}return 0;


查看完整回答
反對 回復 2023-04-11
  • 2 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號