IOS學習筆記 UITableView繫結資料例項

2021-07-15 05:12:17 字數 1033 閱讀 4643

首先建立model,新建乙個檔案存放model類

import uikit

class testmodel: nsobject

}

在controller中的class外,宣告乙個變數

var

list:[testmodel] =

為list增加資料

override func viewdidload()
將table view右鍵拖入類中繫結命名為listtable

@iboutlet weak

var listtable: uitableview!

為table view cell 命名 todocell

在cell中放置乙個label,並設定tag屬性

讓controller類繼承uitableviewdatasource協議,並實現協議:

func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell

右擊storyboard中右擊table view拖拉至控制器,選擇datasource,執行後,可見效果

本是自己的學習筆記,可能寫的比較粗俗,歡迎吐槽

IOS學習筆記

uiview beginanimations view flip context nil 設定動畫塊 uiview setanimationduration 1.25 動畫時間 uiview setanimationcurve uiviewanimationcurveeaseinout 動畫曲線 u...

ios學習筆記

actionsheet 標頭檔案裡加協議。ibaction buttonpressed id sender void actionsheet uiactionsheet actionsheet diddismisswithbuttonindex nsinteger buttonindex 從plis...

ios學習筆記

1.nsselectorfromstring nsstring string 從乙個字串構建乙個selector.2.字串 cocoa處理字串的類nsstring和它的子類nsmutablestring。id stringwithformat nsstring format,指可以接受以逗號分開的多...