iOS開發UI之UITableView的基本使用

2022-08-24 10:18:12 字數 2799 閱讀 1599

**控制項

1. 設定資料來源

- (void

)viewdidload

2. 設定有多少組資料

/*

* * 有多少組資料 */

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview

3. 設定每組有多少行資料

/*

* * 每一組有多少行 */

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

4. 設定每一行的資料

/*

* * 每一行的內容 */

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

ldcar *car =cargroup.cars[indexpath.row];

//1.影象顯示

cell.imageview.image =[uiimage imagenamed:car.icon];

//2.標題文字顯示

cell.textlabel.text =car.name;

//3.子標題顯示

cell.detailtextlabel.text = @"

good!!!";

//4.設定cell右邊的指示器

/*uitableviewcellaccessorycheckmark : 顯示√

uitableviewcellaccessorydetailbutton : 顯示詳情按鈕

uitableviewcellaccessorydetaildisclosurebutton : 顯示詳情按鈕+尖括號

uitableviewcellaccessorydisclosureindicator : 顯示 尖括號

uitableviewcellaccessorynone : 預設右邊指示器什麼也不顯示

*///

4.1 用系統的指示器

cell.accessorytype =uitableviewcellaccessorynone;

定義view顯示到cell右邊

cell.accessoryview =[[uiswitch alloc] init];

//5.設定cell的背景色 backgroundview的優先順序 > backgroundcolor

uiimageview *imageview =[[uiimageview alloc] init];

imageview.image = [uiimage imagenamed:@"

btn_left"];

cell.backgroundview =imageview;

//6.設定選中cell時的背景色

uiimageview *imageview1 =[[uiimageview alloc] init];

imageview1.image = [uiimage imagenamed:@"

img_01"];

cell.selectedbackgroundview =imageview1;

return

cell;

}

5. 組頭部描述

/*

* * 頭部描述 */

- (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section

6. 組尾部描述

- (nsstring *)tableview:(uitableview *)tableview titleforfooterinsection:(nsinteger)section

7. **右邊導航條顯示

/*

* * 返回右邊導航條顯示字串 */

- (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview

1. 監聽選中了哪個cell 

/*

* * 監聽選中了那個cell */

int group = 0

;int row = 0

;- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath

2. 監聽取消選中的cell

/*

* * 監聽取消選中cell */

- (void)tableview:(uitableview *)tableview didenddisplayingheaderview:(uiview *)view forsection:(nsinteger)section

1. 監聽點選了uialertview彈窗上的哪個按鈕

**

*監聽點選了uialertview彈窗上哪個按鈕

*/- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex

IOS 課程 UITable 學習 一

在xib上拖乙個uitableview 並把datasource,delegagte與files owner聯絡。1,介面實現協議 2,用windows 滑鼠左鍵檢視方法內容,在uitableviewdatasource找到必須實現的方法 nsinteger tableview uitablevie...

iOS開發之UI基礎 KVC

k vc key value coding 1.字典轉模型 dic answer dic icon dic title dic options kvc 把字典中的值,賦給當前物件制定的屬性 answer self setvalue dic answer forkeypath answer 遍歷字典中...

IOS開發UI基礎之綜合應用

好處 inte ce viewcontroller property nonatomic,strong nsarray shops end implementation viewcontroller 重寫getter方法 nsarray shops return shops end 獲取plist檔...