我在ProMotion文档和示例中到处查找,但是我无法找到一种方法来更改TableScreen布局,特别是TableView单元格的垂直起始位置。
我的屏幕顶部有一个UIView来显示一些按钮,TableView单元应该从下面开始,但是现在它们是在另一个上面的。
我甚至使用REPL控制台移动了TableView:
rmq(4496872960).nudge d: 10
其中4496872960
是我的UITableViewWrapperView
对象的id,但是我不知道在哪里将这个对象的布局坐标放在代码中。
我的屏幕代码:
class HomeScreen < PM::TableScreen
title I18n.t("home_screen.title")
tab_bar_item title: I18n.t("home_screen.title"), item: "icon-home_32x32.png"
row_height :auto, estimated: 30
stylesheet HomeScreenStylesheet
def on_load
@matches = [{attributes: {status: "dummy1", player2: {email: "dummy1@match.com"}}},{attributes: {status: "dummy2", player2: {email: "dummy2@match.com"}}}]
append(TopHomeView, :top_home_view)
set_nav_bar_button :left, title: I18n.t("home_screen.sign_out_label"), image: image.resource("icon-logout-32x32.png"), action: :sign_out
set_nav_bar_button :right, title: (Auth.current_user ? Auth.current_user["email"] : ""), image: image.resource("icon_user_50x50.png"), action: :open_profile
load_async
end
def table_data
[{
cells: @matches.map do |match|
{
title: match[:attributes][:player2][:email],
subtitle: match[:attributes][:status],
action: :play_round,
arguments: { match: match }
}
end
}]
end
编辑:
我一直试图解决这个问题,现在我在我的UITableViewWrapperView
对象中添加了如下样式:
def viewDidLoad
super
rmq(UITableViewWrapperView).apply_style(:style_for_table_wrapper)
end
因此,在我的样式表中,我可以对所有内容进行样式设置: background_color、隐藏状态,但是框架样式被忽略了。
def top_home_view(st)
st.frame = {l:20, t: 20, w: 300, h: 60}
st.background_color = color.white
end
发布于 2016-07-07 02:52:10
正如在这个Github问题中所指出的:
https://github.com/infinitered/ProMotion/issues/784#issuecomment-230962988
这里的解决方案在于为TableScreen实现一个标头视图。这样我们就可以在单元格上有一个区域供我们自己使用:
定义一个table_header_view,返回一个UIView实例(必需):
class HomeScreen < PM::TableScreen
# ...
def table_header_view
create!(TopHomeView, :top_home_view)
end
注意,"bang方法“(创建!)将返回UIView的实例。
这件事要归功于https://github.com/andrewhavens。
https://stackoverflow.com/questions/38235536
复制相似问题