tableView的使用方法詳解

2021-07-04 18:10:45 字數 2682 閱讀 1160

1 tableview的型別

1.1 uitableviewstyleplain  沒有區頭 不顯區頭     向上滑動區頭不會移動到螢幕外面

』 1.2 uitableviewstylegrouped  有區頭          表滑動,區頭會移動

2 cell accessory   cell的配件

//cell配件(accessory)

// 0 none 什麼也沒有

// 1 disclosureindicator  多了乙個指向右側的按鈕

// 2 detailbutton 詳細資訊按鈕

// 3 checkmark 對勾

// 4 detaildisclosurebutton  詳細資訊按鈕 + 指向右側的箭頭

cell.accessorytype = uitableviewcellaccessorydetaildisclosurebutton;

還可以在設定huadong

3 設定cell 選中狀態

//設定選擇型別 預設為灰底

cell.selectionstyle = uitableviewcellselectionstyledefault;

4 nscopying 協議 作用是只有實現此方法的類就可以呼叫copy方法

系統的某些類是預設實現nscopying協議,諸如nssting,nsarray,nsdictionary等;

所以 之前的people的類的物件預設是不能呼叫copy方法,因為people沒有實現nscopying協議中的copywithzone方法.

臨時字串的引用計數是 -1  nsstring *str = @"laosun";

通過建立字串的物件的方式 引用計數為1 可以進行拷貝 引用計數加 1 效果等同於retain   

nsstring *str1 = [nsstring stringwithformat:@"laosun"];

4.1 淺拷貝 copy

retain拷貝的時指標,物件只有乙個,結果使得物件的引用計數 + 1

4.2 深拷貝  真正意義上的拷貝,只是要產生兩個物件,而且每個物件的引用計數是1

5 //  此屬性就可以代替 設定區頭高度的 協議方法

_tableview.sectionheaderheight = 50;

6 建立tableview所必須的三個方法

6.1  //在tableview上有幾個區域

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview

6.2 //每個區域有多上行

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

6.3  每一行的cell

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

7 相關協議

7.1  區頭需要多個控制項 則可以先建立乙個view,然後再view上新增控制項,view和相關控制項在如下的方法中建立

-(uiview*)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section;

7.2  設定cell的編輯風格

- (uitableviewcelleditingstyle)tableview:(uitableview *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath;

風格型別

7.2.1 uitableviewcelleditingstyledelete      刪除

7.2.2     uitableviewcelleditingstyleinsert 插入

7.2.3 uitableviewcelleditingstylenone        預設

7.3 cell是否可以移動 返回的時乙個bool值

- (bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath

7.3.1 用來移動的三槓

- (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)sourceindexpath toindexpath:(nsindexpath *)destinationindexpath

移動邏輯: 取》刪》新增

7.4  完成編輯

-(void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath;

刪除和插入所做的操作寫在這裡 刪除邏輯:刪除物件 > 刪除行

8  展開閉合邏輯:

通過乙個bool值判斷(_falg[3]),如果是yes則返回相應陣列的count,否則返回0 (在和行相關的方法中),重新整理相應的行的資料

9    表的編輯  增 ,刪 ,移

iOS UIAlertView的使用方法詳細

uialertview的常用方法 標準樣式 uialertview onealertview uialertview alloc initwithtitle 標題 message 提示內容 delegate self cancelbuttontitle 關閉 otherbuttontitles ok...

基於RestTemplate的使用方法 詳解

1.postforobject 傳程式設計客棧入乙個業務物件,返回是乙個string 呼叫方 baseuser baseuser new b程式設計客棧aseuser baseuser.setuserid userid baseuser.setpass pass string postforobje...

UISearchBar 搜尋框 的使用方法詳細

uisearchbar的常用方法 搜尋框 uisearchbar onesearchbar uisearchbar alloc init onesearchbar.frame cgrectmake 0,0,320,70 設定位置和大小 onesearchbar.keyboardtype uikeyb...