JerryWho
JerryWho

Reputation: 3105

iOS RubyMotion: UITableView with instance variable

Using RubyMation to write a TableView I've got the following code. The dataSource is another class. The following code runs fine.

But first I haven't used an instance variable for @dataSource -- just a local variable. The app started all right. But when I started to scroll the app crashed.

So why do I have to use an instance variable?

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

end

Upvotes: 1

Views: 264

Answers (1)

JerryWho
JerryWho

Reputation: 3105

I thought the reason for this behaviour is something with garbage collection. So I googled and found Object initialization in RubyMotion which supports my guess. It seems reasonable to me...

Upvotes: 1

Related Questions