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
@akashgself
在全局范围内显然是未定义的!