Open shiweifu opened 9 years ago
I run the code in my iPhone 6 simulator, the superview's width is 375 and I specify the height of cell is 80.
This is actually an apple thing.
TableViewCells are weird when they are initialized they always are 320 wide no matter what simulator.
try this out (without rmq even)
UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: "test").frame
you will see they will be the sizes you mentioned. Once the table renders the cells they resize to the proper size on the screen. The way I get around this is - instead of styling my cell to be :full
, I use :screen_width
. That should get you going properly.
Also note that cell Heights must be declared in the cell hash, not in the stesheet. Again, this has to do with how Apple designed UITableViews. Make sure to read through the promotion table screen documentation
@markrickert Big thanks.
But I don't know how to set the cell height. I try to set height in tableView's delegate, but it's ineffective.
I just set the cell's contentView frame in rmq_build:
class MainCell < UITableViewCell
def rmq_build
q = rmq(self.contentView)
q.frame = {h: 150, w: rmq.device.width}
# .....
end
end
but I can't set the different height for cell.
In Objective-C project, I usually add a method named + heightForXXXX
in my custom cell, the method return effect height for cell.
so..what's is the best practices for custom cell in rmq?
@shiweifu assuming you are using RMQ only, you can use the delegate methods similar to you'd do it in Objective-C.
def tableView(table_view, heightForRowAtIndexPath: index_path)
# logic to figure out size for your custom cell at index_path is size is
end
If you are using RedPotion then you could also set the height of the cell in the cell hash, like @markrickert mentioned.
@squidpunch
thanks.
but the UITableViewCell's contentView default size always are [320, 44], the cell's contentView is incorrect.
this is wrong height screenshot :
I just return height in UITableViewDelegate:
def tableView(table_view, heightForRowAtIndexPath: index_path)
150
end
right height screenshot
(sorry for it's ugly)
I return the height of cell in delegate and change contentView's default size in rmq_build, it's correct layout.
class MainCell < UITableViewCell
def rmq_build
q = rmq(self.contentView)
q.frame = {h: 150, w: rmq.device.width}
# .....
end
end
but I think It's not a good practice that change the contentView's size in rmq_build
@shiweifu yeah then I am not really sure, sounds like something on the Apple side rather than RMQ. For what it's worth I style the contentView of the cell in my app, because thats what I am appending to - so I make that large enough to contain the views I am making and still control the height of the cell in the delegate. If thats bad practice, I'd watch the thread to see what other suggestions there are!
build view code:
the stylesheet code:
I use rmq.log output current view, the width of cell's contentView always 320 and the height always 44, It's defaults.
I think it's a bug?