这是我要创建的待办事项列表应用程序的代码:
import UIKit
class MyTableViewController: UITableViewController {
var ToDoItems = ["Buy Groceries", "Pickup Laundry", "Wash Car", "Return Library Books", "Complete Assignment"]
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "ToDoCell"
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
cell.textLabel.text = ToDoItems[indexPath.row] //This is where the issue is
return cell
}
最佳答案
安全的方法是使用可选的绑定(bind):
if let label = cell.textLabel {
label.text = ToDoItems[indexPath.row]
}
或者您可以使用可选链:
cell.textLabel?.text = ToDoItems[indexPath.row]
关于ios - 'UILabel ?' does not have a member named ' 文本',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31150885/