2016年9月21日 星期三

Swift/Objective-C 在UIViewController 加入tableView 卻不能正常顯示Cell 內容?

如果在UIViewController.swift 檔案裡

1. Class後面 已經加了UITableViewDelegate 和 UITableViewDataSource
2. data source 沒問題 (eg.  用一個string array)
3. implement I. func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
II. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

兩個方法

而且回傳值也沒什麼問題

那這時候可能是 在 II. method裡面的 let title = UITableViewCell(style:UITableViewCellStyle.,reuseIdentifier: "Cell")

紅色字打錯 而造成 內容顯示不出來.


但這樣還是不會顯示正常內容,因為少了兩行 (至少一行) 程式碼

就是tableView.dataSource = self

P.S 如果需要用到did select 什麼的才要加tableView.delegate = self


沒有留言:

張貼留言