【发布时间】:2014-09-22 13:34:58
【问题描述】:
我正在将核心数据数据库中的对象列表加载到表视图中。
class ScheduleViewController: UITableViewController {
private var items: [AnyObject]?
// MARK: - Table view data source
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let itemCount = items?.count {
return itemCount
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("DayScheduleCell", forIndexPath: indexPath) as DayScheduleCell
if let act = items[indexPath.row] as Activity {
if act.client != nil {
// ...
}
}
return cell
}
}
数据是在闭包中检索的,因此我将 items 数组声明为可选数组,因为它在第一次运行时可能为 nil。
我收到错误 '[AnyObject]?'在这一行if let act = items[indexPath.row] as? Activity 没有名为“下标”的成员。
我不知道如何解决这个问题。
【问题讨论】: