Wil*_*ung 0 uitableview ios swift
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var alphNames = ["ABC","DEF","GHI","JKL","MNO","PQR","STU"]
func tableView(tableView: UITableView, numberofRowInsection section: Int) -> Int {
return alphNames.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath : indexPath) as UITableViewCell
//Configure the cell...
cell.textLabel?.text = departmentNames[indexPath.row]
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
你在numberOfRowsInSection功能上打错了.它是协议的必需功能UITableViewDataSource.它应该是
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return alphNames.count
}
Run Code Online (Sandbox Code Playgroud)
你输入了numberofRowInsection.
| 归档时间: |
|
| 查看次数: |
6329 次 |
| 最近记录: |