【发布时间】:2015-09-29 23:22:41
【问题描述】:
我正在尝试使用 Swift 在 Xcode 中制作 TO-DO 列表应用程序,但在“if let path = indexPath {”行上编写函数方法之一时遇到错误,该行显示“条件中的绑定值”绑定必须是可选类型”。
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不是可选的,因此无需打开它。