Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift UITableView:数据源分配问题_Ios_Uitableview_Swift_Swift Playground - Fatal编程技术网

Ios Swift UITableView:数据源分配问题

Ios Swift UITableView:数据源分配问题,ios,uitableview,swift,swift-playground,Ios,Uitableview,Swift,Swift Playground,这是一个简单的UITableView代码,在操场上正常工作: import UIKit class MyDataSuorce : NSObject, UITableViewDataSource { func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { let cell = 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()
第二个代码有什么问题?

编辑:

let list = UITableView(frame:CGRectMake(0,0,300,300), style: .Plain)
list.dataSource = MyDataSuorce()
list.reloadData()
这是
list.dataSource=MyDataSuorce()
的控制台输出:

游乐场执行失败:错误:错误:无法查找符号:\u memmove

也许我可以解决“为什么?”

我想,这是关于swift变量寿命。(对吗?)


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

MyDataSource()方法的内容是什么?@akashg没有其他代码。您看到的是我所有的代码。请尝试
list.dataSource=self
@akashg
self
在全局范围内显然是未定义的!