I'm building a tableView with custom cells using RubyMotion and ProMotion. I can't figure out why none of the cells are visible. When I'm not trying to use the custom cell class, the title label is visible. What am I missing here? Thanks! Here is my code:
The TableScreen
class HomeScreen < PM::TableScreen
title 'Overview'
def on_load
@welcome_label = UILabel.new
@welcome_label.text = 'Welcome to PushUp'
end
def table_data
data1 = [1, 2, 3]
data = [{ number: 1, date: '1.2.2014' }, { number: 5, date: '2.2.2014' }]
[{
title: 'PushUps',
cells:
data.map do |e|
{ cell_class: MyCell, title: e[:anzahl].to_s, date: e[:datum] }
end
}]
end
end
The custom cell:
class MyCell < PM::TableViewCell
attr_accessor :title, :detail
def layoutSubviews
@title = newTitleLabel
@detail = newDetailLabel
addLabelsToSubview
end
def addLabelsToSubview
Motion::Layout.new do |layout|
layout.view self.contentView
layout.subviews "title" => title, "detail" => detail
layout.vertical "|[title]|"
layout.vertical "|[detail]|"
layout.horizontal "|-[title]-10-[detail]-|"
end
end
def newTitleLabel
label = UILabel.alloc.init
label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
label
end
def newDetailLabel
label = UILabel.alloc.init
label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleFootnote)
label
end
end
Update
Really weird, when I raked this morning, the cell showed 2 labels. They are both sitting on the left, I think it' some kind of standard iOS cell design, so it's not created by me. But they have the values I gave them.
I then deleted everything from the cell class unless the initWithStyle
method (call to super and returning self inside it stayed). The cell stayed the same. This means my cell design has no influence on the design of the cell. Have I maybe failed to declare the cell class the correct way? Thanks!
It appears you're doing the ProMotion part correctly. What version of PM are you using?
Some debugging steps:
MyCell
and see if it shows the title.I have a feeling your issue is with MotionLayout, not ProMotion.