【问题标题】:Swift UITableView : Datasource assigning IssueSwift UITableView:数据源分配问题
【发布时间】:2014-07-11 09:47:23
【问题描述】:

这是一个简单的UITableView 代码,在 Playground 中正常工作

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() 的控制台输出:

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

【问题讨论】:

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

标签: ios uitableview swift swift-playground


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多