Set Cell Subview Position After Height Set? - iphone

In my app I have a tableview, with a custom tableviewcell and that has a UIImageView in it.
However, my issue. - (void)configureCell:(MyCustomCell *)cell atIndexPath:(NSIndexPath *)indexPathwhere I set the frame of my image is called before - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath where I set the cell height.
Meaning, the image position isn't correct (its dynamic, changes depending on cell height).
How do you suggest I get around this?
Thanks.

When do you call your configureCell:atIndexPath: method? In your tableView:cellForRowAtIndexPath: implementation?
Anyway, try to set you image height in tableView:willDisplayCell: delegate method instead. This method is called just bore the cell is displayed on screen so that it will not be resized afterwards by other internal methods.
Besides, can't you use the AutoresizingMask property to make your image view resize automatically depending on its container view (the cell)?

Related

How to set UITableViewCell height Dynamically with its content size to fit?

I want to set frame of content(i.e UILabel in cell) and cell dynamically without set frame of any UIControl programatically.
Elaborate your question with what have u done till now, if your asking for increase the height of the tableview cell you can use the below method.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

UITableView weird padding at the bottom of cell

I have a UITableView in which I am displaying bunch of custom cells. The cell is configured to be 50 pixels in height:
I am retuning 50 in the heightForRow method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50.f
}
But in the end, there's a weird 10-15ish pixel padding/spacing between each cell:
What am i doing wrong?
Thanks!
Without seeing your custom cell's configuration code, I can only guess. The space you see is likely internal to the cell. Perhaps you've added a green subview, but it isn't sized to fit the cell. You probably need to set the subview to have a flexible height (or if you're using Auto Layout, pin the top and bottom to the parent).
Or maybe you have one cell per section and you're somehow creating a blank header or footer.

How to increase area that allows tapping on tableviewcell image?

I have a tableview cell with a custom image in the imageview of the cell. However, sometimes if you tap on the image (a checkbox), it taps on the actual cell instead of the image. I want to make it so if you tap part of the cell around the image, the checkbox is checked instead of the actual cell. How would I do this?
This is some code..
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell.imageView.image = [UIImage imageNamed:#"unchecked.png"];
The image is a 28x28 image.
One simple way to solve this is to increase the width of the cell's image view.
Probably the easiest way would be to create UITapGestureRecognizer and add it to cell.contentView using the same selector you are using for image tapping.

UITableviewcell spacing between cells

I am creating UITableView cells dynamically and adding three labels on to it.I made my table as transparent by opaque no and clearcolor.
But the cells are being shown without spaces.I need to give space between cells.
Actually if i load a custom UITableViewCell from the xib file the space comes automatically. How to solve this issue?
UITableView with custom spacing
You can do this by cheating the tableView cell. By default you can only specify a single line, etched line or none so here is an alternative. You'll need to override the tableView delegate method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Calculate your cell height with its contents, margin/padding/line width and return it. Set the background color of the cell to [UIColor clearColor] and make your table background the desired color for your separator. Subclass UITableViewCell and attach a backgroundContainerView and make it the desired background color for your cell. Attach all the subview to that backgroundContainerView.
Finally, in the UITableViewCell subclass implement
- (void)layoutSubviews
Here you should layout the subviews with the container view as if that is the whole cell.
In UITableView you have 2 properties : separatorStyle and separatorColor. Use them maybe your separator color is clearcolor so try and change it.
This problem is due to the difference in height in TableView and Custom cell. Set the cell height in heightForRowAtIndexPath delegate.

Drawing selected state on custom UITableViewCell

I have a customer UITableViewCell whose whole display is drawn indrawRect. When it draws it creates CGLayers so that it can reuse certain pieces when something is changed.
I have changed my UITableViewCellSelectionStyle to "None" because I don't want the default selected view to cover my drawing.
My problem is that I call setNeedsDisplay in setSelected:animated: for my cell but by the time drawRect is called, setSelected:animated: has already been called again to deselect the cell. In my table view controller didSelectRowAtIndexPath, I call deselectRowAtIndexPath as Apple advises.
EDIT - I have also tried called the setNeedsDisplay on my cell from my table view controller's (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath but that didn't change anything.
Any ideas? Thanks.
Use the table cell's selectedBackgroundView property. If you assign a custom view to that, it'll get shown and hidden at the same time as the default selection backgrounds—in other words, without having to wait for the setNeedsDisplay to get around to calling drawRect: on the cell itself.