Swift UITableView:数据源分配问题



这是一个简单的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()的控制台输出:

游乐场执行失败:error: error: could 't lookup symbols: _memmove

也许我解决"为什么? "…

我想,这是关于swift变量的生命周期。(对吗?)

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

最新更新