ios - 表格 View 错误

标签 ios uitableview swift

我是 Swift 和 IOS 编程的新手,但我试图使用 TableView 加载一些数据,但我收到了一个我以前从未见过的错误。有人可以帮帮我吗?错误出现在我试图传递我创建的数组的单元格文本标签的行上。错误是“找不到接受提供的参数的下标重载” enter image description here

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/

相关文章:

ios - Swift 中带有生成器和序列的泛型

c# - 如何使用 segue 传递对象

ios - 尝试使用闭包在 ViewController 之间传递数据时我犯了什么错误?

swift - 快速设置我的条形图的水平滚动

iphone - 从 UITableView 中删除单元格 - 错误

iOS系统按钮点击框问题

ios - iOS 中额外的 CALayer 的子层

ios - 正确的保存日期和值(value)的结构

ios - 如何让 scrollview 将触摸事件传递给 superview?

ios - 如何在后台 iOS Swift 中播放实时流中的音频