我正在使用RubyMotion和ProMotion构建一个带有自定义单元格的ProMotion。我不明白为什么所有的细胞都看不见。当我不尝试使用自定义单元格类时,标题标签是可见的。我在这里错过了什么?谢谢!这是我的代码:
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
自定义单元格:
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
更新
真奇怪,今天早上我耙的时候,手机上有两个标签。他们都坐在左边,我想这是一种标准的iOS细胞设计,所以不是我创造的。但他们有我给他们的价值。
然后,我删除了单元格类中的所有内容,除非initWithStyle
方法(调用Super并在其中返回self )。牢房没变。这意味着我的小区设计对电池的设计没有影响。我是否没有以正确的方式声明单元格类?谢谢!
发布于 2014-06-09 14:48:11
看来您做的ProMotion部分是正确的。您使用的是什么版本的PM?
一些调试步骤:
MyCell
中的所有内容,看看它是否显示标题。我觉得你的问题是MotionLayout,而不是ProMotion。
https://stackoverflow.com/questions/24105868
复制相似问题