iOS開發學習筆記二:UITableView

來源:互聯網
上載者:User

標籤:

一:TableViewController

1:刪掉預設的ViewController 拖動一個TableViewController

2:建立一個Cocoa Touch Class,命名為:TableViewController

3:將1邦定至2

4:拖動一個Label,TAG設為1,將CELL的ID設為cell

相關代碼:

 1     override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 2  3         return 1 4     } 5  6     override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 7  8         return 4 9     }10 11     12     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {13         let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell14         15         var label=cell.viewWithTag(1) as UILabel16         17         label.text="你好,哈哈哈"18        19         return cell20     }

二:TableView

1,拖動一個TableView

2,建立一個Cocoa Touch Class,命名為:MyTV

3,將1和2綁定,拖動一個cell至TableView,命名為cell

4,拖一個label,TAG設為1

相關代碼:

 1 class MyTV: UITableView,UITableViewDataSource { 2  3      4   let data=["你好,我是一個人","didisswfids","w也是在要工"]
 5      6     required init(coder aDecoder:NSCoder) 7     { 8         super.init(coder: aDecoder) 9         self.dataSource=self10     }11     12     func numberOfSectionsInTableView(tableView: UITableView) -> Int {13         return 114     }15     16     17     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {18         return 419     }20 21     22     23     24     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {25         26 27         let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell28         29         var label=cell.viewWithTag(1) as UILabel30         31         label.text=data[indexPath.row]
32         33         return cell34     }35 }

 

iOS開發學習筆記二:UITableView

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.