0

这是一个在操场上正常工作的简单UITableView代码:

import UIKit

class MyDataSuorce : NSObject, UITableViewDataSource {
    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
    {
        let cell = UITableViewCell(style: .Value2, reuseIdentifier: nil)

        cell.textLabel.text = "Row #\(indexPath.row)"

        return cell;
    }

    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
    {
        return 4
    }

}


let list = UITableView(frame:CGRectMake(0,0,300,300), style: .Plain)
let d = MyDataSuorce()
list.dataSource = d
list.reloadData()

但是当我第一次尝试这段代码时,它不起作用,只显示一个空的UITableView

let list = UITableView(frame:CGRectMake(0,0,300,300), style: .Plain)
list.dataSource = MyDataSuorce()
list.reloadData()

第二个代码有什么问题?

编辑:

这是控制台输出list.dataSource = MyDataSuorce()

Playground 执行失败:错误:错误:无法查找符号:_memmove

4

1 回答 1

1

也许我解决了“为什么? ”......

我认为,这与快速变量生命周期有关。(正确的?)

在第二个代码中,我只是忘记了返回的对象 (by MyDataSource()) 将在该行代码中存在。

于 2014-07-11T11:01:11.000 回答