我是 Swift 和 IOS 编程的新手,但我试图使用 TableView 加载一些数据,但我收到了一个我以前从未见过的错误。有人可以帮帮我吗?错误出现在我试图传递我创建的数组的单元格文本标签的行上。错误是“找不到接受提供的参数的下标重载”
import UIKit
class ViewController: UIViewController, UITableViewDelegate {
var cellContent = [1,2,3]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellContent.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel?.text = cellContent[indexPath.row]
return cell
}
最佳答案
看起来这个错误有点误导。这里的实际问题似乎是您试图将 Int
设置为 String
属性。你可以这样做:
cell.textLabel?.text = String(cellContent[indexPath.row])
通过此更改,您的代码对我来说工作正常。
关于ios - 表格 View 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29859463/