-3

我在 Xcode 版本 9.2 (9C40b) 中使用 swift 得到了这些错误

  1. 二元运算符“*”不能应用于“IndexPath”和“Float”类型的操作数
  2. 对成员 'tableView(_:numberOfRowsInSection:)' 的模糊引用
@IBOutlet weak var slider: UISlider!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 50
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
    cell.textLabel?.text = String(indexPath * slider.value)
    return cell
}

@IBAction func sliderValueChange(_ sender: Any) {
    tableView.reloadData()
}
4

1 回答 1

-1

试试这个 :

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
    cell.textLabel?.text = String(slider.value * Float(indexPath.row))
    return cell

}
于 2018-01-22T12:05:58.193 回答