remove spacing between custom cells in grouped style of UITableViewCell - ios

In my application, I am using custom table cells to populate UITableView (grouped). The tableView has only one section, and this section has 4 rows. however, I see an unwanted gap between the rows. How to remove this gap?
I am using a background view for the tableView:
In viewdidLoad, i have done
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bluegrad.png"]];
self.customerCareTableView.backgroundView = imageView1;
And what i am getting is:
this is what i want

First suggestion for this cases (even though you already tried this) is checking that the separatorStyle property of your tableview is correctly settled to UITableViewCellSeparatorStyleNone for not having a
separator at all.
When using custom assets as background images, be sure to have the image resource sliced correctly. There shouldn't be any extra pixels neither in the bottom nor top of those assets. You can check this using another app like Preview.
Double check that you are setting the proper height of your cell, must be the same height of your background image. You should check that on the following method, (also you may want to check if there is any kind of constraint that may be causing a resize of your image at runtime
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Hope this helps!

Related

IOS/Objective-C: Reusing Cell Throws off Autolayout of Different Size Elements in TableviewCell

I am displaying feed items in a tableview. Depending on the item, the cell must be larger or smaller--for example larger to accomodate a photo or larger still if it references another feed item such as an article and I have to display the item referenced.
In most cases, I've used autolayout to get the cells to auto expand or contract based on the content. However, in a couple cases, this was proving next to impossible so I reset the value of a constraint in code. For example, if there is no photo in one case, I shrink the height of the cell in code as the cell was not shrinking on its own.
This works fine when the page loads. But when you scroll and reuse cells, it leads to weird effects such as the cell expanding vertically or lines being pushed into one another.
Some questions on SO suggest using the method:
-(void) tableView:(UITableView *)tableView didEndDisplayingCell:(IDFeedCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//Undo changes here
}
The problem is I don't know how to undo changes. For example, if I made a cell smaller by setting
self.height.constant = 100;
Should I set it back to the constant value in storyboard?
What value can I set it to when I don't know what the next item to resuse the cell will need in the way of dimensions.
Thanks for any suggestions. BTW, autolayout shows no issues.

ios dynamic cell height determined by photos and text

I am trying to make a feed very similar to Instagram, everything works however I have ran into a problem I cannot figure out how to solve.
This feed will include photos that are of different sizes, e.g squares, portrait photos and landscape photos.
The problem is I want to resize the UIImageView in the UITableViewCell to match the size of the photo, and also have the UILabel resize depending on how much text there is.
The UIImageView's width will always equal the width of the screen, like Instagram, and only its height will change to make sure the photos are of correct ratio.
Here is a photo of my current cell:
I have tried using autolayout, however I couldn't understand how to get it to work with a UIImageView that will change ratio, from being landscape orientation to portrait orientation etc.
I have also tried in this method here :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
Manually trying to calculate the size:
//An example of trying to calculate the size of a view in my cell
cell.cellView.frame = CGRectMake(0, 0, self.view.frame.size.width, 400);
However, it has gotten extremely complicated that way because I don't know how to resize the actual UITableViewCell height to be unique for every cell.
I have also looked at the following resources:
Link 1
Link 2
Link 3
Link 4
Link 5
All of these are tutorials on dynamic cell height, however they do not seem to explain what to do with my situation.
It would be great if anyone could please suggest what I can do to achieve the Instagram style feed with unique cell heights and unique content size within the cells.
As far as I can tell from looking at the app, each item in the feed is actually a whole section in the tableview. The giveaway is the way the username/location/time header 'snaps' into place at the top and everything else scrolls under it. That's a viewForHeaderInSection. Each section then has 2 or more rows: the photo, the toolbar, the hearts/likes info, and then one row per comment.
So instead of making one giant cell and trying to lay everything out inside it, use multiple cells. You can prototype each cell in the storyboard with a unique reuse identifier, then just figure out what kind of cell you're looking at and dequeue the appropriate one from the storyboard.

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.

What are these UITableView lines in the image?

I have a UITableView on a UIView. This UIView is in a UICollectionViewCell which means that I can do the action you can see in the image. A new UICollectionViewCell is coming on from the right. As a new cell comes onto the visible rect it is slightly resized you can see that the right one is slightly smaller.
While this new cell is "sliding on" the table view has some black lines that show through. It is not the actual separator lines as you can clearly see them, further turning them off or making them the same colour as the cell does not change things.
So can anyone tell me what these black lines are and if I can either directly get rid of them or cover them over somehow.
I believe that the lines are cell separators. You could set the separatorStyle property to UITableViewCellSeparatorStyleNone.
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

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

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.

Resources