Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if view in UITableViewCell contentView, the :full option for frame is wrong #300

Open
shiweifu opened this issue Aug 30, 2015 · 7 comments

Comments

@shiweifu
Copy link

build view code:


  def rmq_build
    rmq(self).apply_style :main_cell

    q = rmq(self.contentView)
    @top_view    = q.append(UIView, :top_view).get

  end

the stylesheet code:

  def top_view(st)
    st.background_color = color.yellow
    st.frame = {h: 50, w: :full}
  end

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?

@shiweifu
Copy link
Author

I run the code in my iPhone 6 simulator, the superview's width is 375 and I specify the height of cell is 80.

@squidpunch
Copy link
Contributor

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.

@markrickert
Copy link
Member

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

@shiweifu
Copy link
Author

@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?

@squidpunch
Copy link
Contributor

@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.

@shiweifu
Copy link
Author

@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

@squidpunch
Copy link
Contributor

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants