gpt4 book ai didi

ios - 类型 'ViewController' 不符合协议(protocol) 'UITableViewDataSource'

转载 作者:行者123 更新时间:2023-11-28 10:01:21 27 4
gpt4 key购买 nike

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
}

}

最佳答案

您在 numberOfRowsInSection 函数中输入错误。它是UITableViewDataSource 协议(protocol)的必需 函数。应该是

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return alphNames.count
}

您输入的是 numberofRowInsection

关于ios - 类型 'ViewController' 不符合协议(protocol) 'UITableViewDataSource',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28322531/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com