iOS RubyMotion:带实例变量的UITableView

时间:2013-04-28 17:03:02

标签: uitableview rubymotion

使用RubyMation编写TableView我得到了以下代码。 dataSource是另一个类。以下代码运行正常。

但首先我没有为@dataSource使用实例变量 - 只是一个局部变量。 该应用程序开始没事。但是当我开始滚动应用程序崩溃时。

那么为什么我必须使用实例变量?

TIA, JW

class FolderController < UIViewController

  def viewDidLoad
    super

    self.title = "Folder"

    @table = UITableView.alloc.initWithFrame(self.view.bounds)
    self.view.addSubview @table

    # fine
    @dataSource = DatasourceFolder.new
    @table.dataSource = @dataSource

    # crashes when scrolling the tableview 
    # dataSource = DatasourceFolder.new
    # @table.dataSource = dataSource

 end

1 个答案:

答案 0 :(得分:1)

我认为这种行为的原因是垃圾收集。所以我用Google搜索并发现Object initialization in RubyMotion支持我的猜测。这对我来说似乎很合理......