Tim*_*RIM 5 uitableview ios swift
我无法使用swift编程语言在tableview中显示数组元素.我做了一些研究,但无法解决问题.下面,您可以从这里看到我的代码并将项目下载为.zip文件:http://1drv.ms/1Ca2hyp
我也可以发一些视频.他们是11分10秒.总共很长
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var myTableView: UITableView!
var cars = [String]()
var newCar: String = ""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
cars = ["BMW","Audi", "Volkswagen"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cars.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = cars[indexPath.row]
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
您忘记将控制器注册为UITableView的dataSource.
将其添加到您的代码中:
@IBOutlet var myTableView: UITableView! {
didSet {
myTableView.dataSource = self
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25110 次 |
| 最近记录: |