一、uitableview
1.資料展示的條件
1> uitableview的所有資料都是由資料來源(datasource)提供的,所以要想在uitableview展示資料,必須設定uitableview的datasource資料來源物件
2> 要想當uitableview的datasource物件,必須遵守uitableviewdatasource協議,實現相應的資料來源方法
3> 當uitableview想要展示資料的時候,就會給資料來源傳送訊息(呼叫資料來源方法),uitableview會根據方法返回值決定展示怎樣的資料
2.資料展示的過程
1> 先呼叫資料來源的
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview
得知一共有多少組
2> 然後呼叫資料來源的
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section
得知第section組一共有多少行
3> 然後呼叫資料來源的
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
得知第indexpath.section組 第indexpath.row 行顯示怎樣的cell(顯示什麼內容)
3.常見資料來源方法
1> 一共有多少組
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview
2> 第section組一共有多少行
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section
3> 第indexpath.section組 第indexpath.row行顯示怎樣的cell(顯示什麼內容)
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
4> 第section組顯示怎樣的頭部標題
- (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section;
5> 第section組顯示怎樣的尾部標題
- (nsstring *)tableview:(uitableview *)tableview titleforfooterinsection:(nsinteger)section;
4.tableview重新整理資料的方式
1> 修改模型資料
2> 重新整理**
* reloaddata 整體重新整理(每一行都會重新整理)
* - (void)reloadrowsatindexpaths:(nsarray *)indexpaths withrowanimation:(uitableviewrowanimation)animation
區域性重新整理
//區域性section重新整理
nsindexset * nd=[[nsindexset alloc]initwithindex:1];//
重新整理第二個section
[tview reloadsections:nd withrowanimation:uitableviewrowanimationautomatic];
//區域性cell重新整理 www.2cto.com
nsindexpath *te=[nsindexpath indexpathforrow:2 insection:0];//
重新整理第乙個section的第二行
[tableview reloadrowsatindexpaths:[nsarray arraywithobjects:te,nil] withrowanimation:uitableviewrowanimationmiddle];
重新整理動畫:
typedef ns_enum(nsinteger, uitableviewrowanimation) ;
5.效能優化
1> 定義乙個迴圈利用標識
static nsstring *id = @"c1";
2> 從快取池中取出可迴圈利用的cell
uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:id];
3> 如果快取池中沒有可迴圈利用的cell
if (cell == nil) {
cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:id];
4> 覆蓋cell上面的資料
cell.textlabel.text = [nsstring stringwithformat:@"第%d行資料", indexpath.row];
iOS 中tableview的使用
section總數 nsarray sectionindextitlesfortab leview uitableview tableview section titles 每個section顯示的標題 nsstring tableview uitableview tableview titlefo...
iOS中tableView的cell的重用機制
因為最近鋪介面是用到了tableview,所以我就研究了一下tableview的重用機制.tableview的重用機制.剛接觸tableview時我就研究了一下它的重用機制,但是時間長了就有點忘記了,最近老師布置了有關tableview的作業使我又想起了它,所以今天又複習了一下,有不足的地方請大家見...
ios中tableview的移動新增刪除
mjviewcontroller.m uitableview 編輯模式 created by mj on 13 4 11.import mjviewcontroller.h inte ce mjviewcontroller property nonatomic,retain nsmutablearr...