How to avoid cells background image from hiding the separator line between rows - ios

In my table view I am using custom image for the UITableView cell's background. It works perfectly except for the fact it hides the row separator. And now there is no row visible.
Is there a way to increase the distance so that cells will get separated.
Please help!!!
Thanks,

Without seeing what you are seeing, it's a bit hard to tell. That said, you could try adding the separator to the image so that it shows up in the cell.
If you want to change the height of the cell, implement the -tableView:heightForRowAtIndexPath: method in the table view delegate. Just return the correct height for the row at indexPath. I believe there is also a way to set the rowHeight in the table view properties in interface builder if all cells will be the same, but I tend to stay away from IB when possible.

As far as my knowledge you can add a line image to the cell as a footer.So that you can see the separator

I believe you have to override the -setFrame: method in your custom cell and return the same frame with height minus 1 pixel.
Also be sure to call [super layoutSubviews]; in your -layoutSubviews method if you have overridden this method with some custom implementation.

LineSeparator may be invisible to you because of your background image in your cell. Try to change the style of your separator.
Alternative Way:
Otherwise You have to add a one pixel line to the bottom of your Custom cell background image by your designer and if it's still not visible in your tableView, then you have to increase a height for your cell in heightForRowAtIndexPath: method.

Make sure your view if you have one that is inside your Cell is exactly the same size as your cell's size.
Make sure:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
is setting your cell heights correctly for all cells.

Related

TableViewCell with SegmentControl

I have tableview in which a particular cell has the UISegmentedControl in it.
My doubt is when a particular segment is selected I need to expand the cell and show the information below and need to hide it when the other segment is selected.
For Ex:
I have three segment A, B and C. When selecting the segment B, I need to show switch below the segment and when the other two segments are selected nothing must be displayed below the segment.
Your dataSource's objects should have an "extended" property.
Each time a segmentedControl is changed, update your dataSource accordingly and reload your cell.
When you configure your cell, change its size depending on the "extended" property of the object.
Theres a few things to do here. You need to make sure your tableview is using automatic dimension for its cell height. Dont use the -heightForRowAtIndexPath method (remove it). Instead set two properties on the tableview :
[self.tableview setEstimatedRowHeight:110];
[self.tableview setRowHeight:UITableViewAutomaticDimension];
This enables proper autolayout (in case you havent already) for each cell.
You will need to have a subclass of UITableViewCell in code, if you havent already (sorry for skipping over some quite big things!). Add the information label to your cell in Interface Builder. Give it a height constraint, and then drag this height constraint into your cell subclass so you can change it.
Now put your code for handling the segmented control in the subclass. When you detect that the central segment has been selected, then affect the height constraint of your information label, like this :
self.labelHeightConstraint.constant = 40;
You may also need a call to setNeedsLayout :
[self setNeedsLayout];
Apologies for the brevity - hopefully this will point you in the right direction. There are some other details - for eg on -prepareForReuse method (on the cell) you can set the height of the info label to 0 (and call setNeedsLayout again).

UiCollectionView and expandable view

I have got UiCollectionView with rounded cel (on iPad 3-4, on iPhone 1-2).
I need show view below any clicked cell as on screen (with change text length).
I spend a lot of time thinking about this.
My first step was make custom cell that show the frame below cells, but it was wrong step.
Rounded cells changed padding when this was added...
I am using RAReorderableLayout, additionally to swipe cells.
Any idea?
Please help me with this problem.
You could make it a custom UIView, which has 3 parts: the part before the tick, the image with the tick and the part after. Then in the delegate method for
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
you can call an update method on this view, that will change the widths of the three parts according to the selected index in the collection view.
You could even send the width of the collection view cell in this update method to use it for calculating the right widths.
Hope this helps! Good luck!

UITableViewCell size does not follow Content View size

I have two UITableViewControllers which use the same set of cell templates, therefore I have created a table view controller in my Storyboard which contains these templates. My table view controllers instantiate an instance of this template holder tableview, then in -tableView:cellForRowAtIndexPath: they deque one of it's cells, and configure it as they need.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *widgetDict = [self.widgets objectAtIndex:indexPath.row];
DMSWidget *widget = [self.widgetStorageTableViewController.tableView dequeueReusableCellWithIdentifier:#"Key Value Row"];
...
return widget;
}
These cells have their inner layouts set up entirely using AutoLayout.
Everything works fine, except that I get cells which have the standard 44 px height and width of the table view, with Content Views narrower than this (depending which they contain, the ones with less contents are smaller), and are longer than the cells themselves. So the Content Views overlap the next cell but don't fill the entire width.
I don't understand, how this could happen. How is it possible, that the UITableViewCell has different size than it's Content View? They should be the same, isn't it?
What I tried to do but failed:
implement -tableView:heightForRowatIndexPath:: tried to return UITableViewAutomaticDimension, but did not help
reload my table view when the sizes are calculated: does nothing
add hacks to cell implementations, like setting autoresizingMask in -awakeFromNib: I could make the Content View expand to the width of the cell itself, but it was still overlapping to the next cell
UPDATE: It looks like it is not related to the dual table view architecture. When I copy my cell to the tableView where it will show up, has the same issues.
I've found the solution: it was all my fault. In some of the ancestors of my cell has an init, which called -initWithFrame: explicitly with CGRectZero. After removing this, iOS 8 could use it's frame values and everything worked fine.

heightForRow not equal cell height in UITableView?

I have created a viewController which displays a plain style UITableView. Sometimes I have enough cells to fill up the table view, sometimes I don't. When I don't have enough cells I want to make the table view smaller, in order to fill the rest of the screen with a view that displays the same background color as the color of my cells.
To do that I multiply the heightForRow with the number of cells that the table view is about to display. I have set the heightForRow to 70 and I have set the height of my custom cells to 70. This does make my table view smaller than even one of my cells.
Is the tableView height calculated in a different way, or what am I doing wrong?
EDIT: The answer below did not answer my question, but it solved my problem.
I use:
[yourtable setTableFooterView:[[UIView alloc] init]];

UITableViewCell frame height not matching tableView:heightForRowAtIndexPath:

I'm constructing a UITableView with variable height custom table cells, their height determined by the size of a contained multi-line UILabel. I've got the tableView:heightForRowAtIndexPath: delegate method wired up and calculating the final height correctly using sizeWithFont:constrainedToSize:.
I've run across strange issue: by the time the data source method tableView:cellForRowAtIndexPath: is called, the correct per-row height has already been determined as described above, but the frame of the cell does not match that height. Instead, the frame.size.height property of the cell is the default cell height of the table view (86 px, as I've set it in Interface Builder, the correct height when the contained UILabel has just one line of text), instead of being the height that tableView:heightForRowAtIndexPath: determined correct for that index path.
I'm producing the cells in cellForRowAtIndexPath: using dequeuing, that is,
// Using storyboards, this never returns nil, no need to check for it
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:#"SomeIdentifier"];
NSLog(#"%f", cell.frame.size.height); // 86, not correct if the cell contains a multi-line UILabel
It seems, then, that whatever iOS is doing behind the scenes, the dequeuing is not setting the frame property of the cell to match the calculated height. This in itself is not that surprising, dequeuing concerns itself with cell instances, not their geometry. The cells are rendered correctly, though, so the height property is being set somewhere, but it happens after cellForRowAtIndexPath:.
So: when I initially populate the table view, cell.frame.size.height is 86 for all the cells as they appear for the first time when I scroll the list downwards. Since the correct geometry is set sometime after the first cellForRowAtIndexPath: for each row before it's displayed, when I scroll back up, the height property is correct for each cell that comes back into view after being reused.
After this I can scroll the table view back and forth at will, and the height property remains correct for each cell from that point on.
What's the correct way of getting the correct cell height the first time around, before any dequeue-based reuse happens? I need this to do a bit of re-positioning of the subviews of the table cell. Do I need to manually call heightForRowAtIndexPath: in cellForRowAtIndexPath: and then manually set the frame of the freshly created CustomCell instance to match that height? This seems redundant, and I'd need to create a mechanism to detect when the cell is created for the first time with the wrong frame height vs. when it is dequeued with the correct frame height later to avoid this redundancy.
So, if someone can shed some light into what the logic is behind this, I'd appreciate it.
As suggested by Flexo, answering this myself is apparently better than adding an edit to the question. So, here's the previous edit as an answer:
Nevermind, I should read the docs better. I can get the correct frame in the tableView:willDisplayCell:forRowAtIndexPath: method of UITableViewDelegate, so that is the correct place to do subview customization that relies on the correct frame being set, not cellForRowAtIndexPath:.
Interesting that the docs say this, though:
After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.
...since the correct frame is already there when this delegate method is called. But anyway, problem solved.
Don't forget that the cell is a UIView, so overriding layoutSubviews is also a valid way to get the correct frame and adjust size/position of subviews. Just don't forget to call [super layoutSubviews].
Easiest way I found was just to call cell.layoutIfNeeded() before you do any setup on the cell. This makes sure all the layout constraints are calculated and the frames are set.

Resources