Seb*_*bbe 0 xcode uitableview ios swift
如何在 UIViewController 中填充 UITableView?UITableView 是动态的并使用原型单元格。
(使用斯威夫特)
执行以下操作:
import UIKit
class tableViewOne: UIViewController{
@IBOutlet var tableView: UITableView!
// your data
var dummyData = ["data 0","data 1","data 2"]
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension tableViewOne: UITableViewDataSource, UITableViewDelegate {
// Define no of rows in your tableView
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dummyData.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Default cell
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")! as UITableViewCell
cell.textLabel!.text = dummyData[indexPath.row]
return cell;
}
}
Run Code Online (Sandbox Code Playgroud)
注意:不要忘记DataSource在. 如果已经在.DelegateUITableViewstoryboardstoryboard
| 归档时间: |
|
| 查看次数: |
5575 次 |
| 最近记录: |