Closed andersennl closed 9 years ago
I'll check into this a bit later today. I think that is a starting point for a cell height - but the table delegates are going to take over and resizing based on the content and/or defaults.
UITableViewCell heights are not governed by stylesheets, they're governed by the UITableViewDelegate methods, which are handily abstracted for you in ProMotion, so if you're using a PM::TableScreen, just return a cell hash back with the height you want:
{
title: "Whatever",
action: :whatever,
height: 70
}
Documentation here: https://github.com/clearsightstudio/ProMotion/blob/master/docs/Reference/API%20Reference%20-%20ProMotion%20Table%20-%20Cell%20Options.md
If You're using a standard old UITableView, you'll have to set the table's delegate to self
and then implement this method: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/
Thanks a lot for your fast reply. I'm using a PM::TableScreen and I'm a little confused now. If the stylesheets dont have any influence on the cell, why does the redpotion generator generate the my_cell_height
method? I thought it is supposed to regulate the cell's height?
The generator is meant to give you a place to set the height in a stylesheet and then reference it in your cell hash in the controller, essentially keeping all your view logic all in the same place.
Check out the comments at the end of the generated cell view: potion create table_screen_cell bar_cell
then look in /app/views/bar_cell.rb
You can use this like so in your table_screen:
def table_data
[
{
title: "Section",
cells: [
{ cell_class: BarCell, height: stylesheet.bar_cell_height, title: "Foo"},
{ cell_class: BarCell, height: stylesheet.bar_cell_height, title: "Bar"}
]
}
]
end
Sorry, I don't mean to annoy you but I stil find this confusing. I just created a test cell, this is the generated code:
module TestCellStylesheet
def test_cell_height
40
end
def test_cell(st)
st.frame = {l: 5, t: 100, w: 80, h: test_cell_height} # <--- this is unusable, right?
st.background_color = color.light_gray
# Style overall view here
end
def test_cell_title(st)
st.frame = {l: 10, fr: 0, centered: :vertical, h: 20}
st.font = font.medium
st.color = color.black
end
end
...
I use this code in my controller:
def table_data
[
{
title: "test",
cells: [
{ cell_class: TestCell, height: stylesheet.test_cell_height, # line 20
},
]
},
]
end
Then this is the error I get:
*** Terminating app due to uncaught exception 'NoMethodError', reason: 'settings_table_screen.rb:20:in `table_data': undefined method `test_cell_height' for nil:NilClass (NoMethodError)
from table.rb:31:in `promotion_table_data'
from table.rb:94:in `editable?'
from table.rb:103:in `set_up_accessibility'
from table.rb:23:in `screen_setup'
from support.rb:17:in `try:'
from screen_module.rb:20:in `screen_init:'
from table_view_controller.rb:5:in `new:'
from app_delegate.rb:9:in `on_load:'
from delegate_module.rb:16:in `application:didFinishLaunchingWithOptions:'
No problem at all... did you include that module in your stylesheet for the PM::TableScreen?
Should be something like:
class SettingsTableScreenStylesheet < ApplicationStylesheet
include TestCellStylesheet # if this line isn't here, your tablescreen won't know about the new cell's style
# other styles here
end
and in your tablescreen:
class SettingsTableScreen < PM::tableScreen
stylesheet SettingsTableScreenStylesheet
# other stuff here
end
hey @andersennl no annoyance at all!
*\ Terminating app due to uncaught exception 'NoMethodError', reason: 'settings_table_screen.rb:20:in
table_data': undefined method
test_cell_height' for nil:NilClass (NoMethodError)
So when this is fired the stylesheet is nil. do you have the stylesheet set in the screen like @markrickert listed above?
Yes, everything is included like in the example above. I was about to write that about the NoMethodError
from the nil class as well. I've double checked the names... this is so weird..
ok, let me see if I can reproduce this, unless you have a public repo with the problem I can pull down and help debug?
That you both so much for your time. My project isn't online, it's mostly really basic, though. If you generate a table and a cell, you basically have my code ;)
@andersennl throwing together a quick project and see if I can help figure it out :+1:
im going to reopen this issue - 95% sure I can reproduce this bug!
I'll try and get a PR out to fix it this evening, sadly I cant work on it now as I have prior plans - but I have a local repo that I can reproduce the bug - thanks for reporting this @andersennl
You are welcome, thanks again for your help!
@andersennl as a work around, you should be able to do this.
def table_data
[
{
title: "test",
cells: [
{ cell_class: TestCell, height: 40
},
]
},
]
end
Yes that works, thanks! @squidpunch
@markrickert if you, or someone else wants to work on this before I get to it, feel free!
Essentially the problem is an order of operations. When we call table_data
the stylesheet is not set, its being set later in the process - but we've got to figure out why it,s not set before table_data
I can check it out later tonight (or more likely tomorrow AM) if someone doesn't work on a PR before I get to it :smile:
Hi, following example code:
No matter what I enter as
my_cell_height
(e.g. 300 or 10), the actual height of the cell doesn't change. I've tried with different cells and different heights but nothing happens. As the redpotion generator generates the code regarding the height, I assume this is the correct (and only) place to change the height.This is what the
log
tells me:What am I missing? Thanks!