我正在尝试使用 Swift 在 Xcode 中制作一个 TO-DO 列表应用程序,但我在“if let path = indexPath {”行中编写其中一个函数方法时遇到错误,该行显示“条件中的绑定(bind)值”绑定(bind)必须是 Optional 类型”。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
if let path = indexPath {
let currentString = dataSource[path.section][path.row]
cell.textLabel?.text = currentString
}
return cell
}
最佳答案
因为 indexpath
不是可选的,所以你不需要使用条件绑定(bind)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let currentString = dataSource[indexPath.section][indexPath.row]
cell.textLabel?.text = currentString
return cell
}
关于ios - 条件绑定(bind)中的绑定(bind)值必须是可选类型 [IOS - SWIFT],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353834/