TableView Cells Overlapping UIView After Scrolling Down and Up - ios

I'm playing around with some design concepts and I got stuck with this "bug."
Any idea why is this happening? I've iterated through different things and still can't find the culprit or solution to this.
This "circle" for the price, overlapping the other cell at the bottom of it is my intended design. This is all good, however, when I scroll down and back up, "older" cells suddenly overlaps the "circle."
Kindly see the screenshot. Any help is much appreciated!!!
Has anyone experienced this before?
iOS9 - Xcode 7.3.1
EDIT:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("CategoryCell") as? CategoryCell {
cell.selectionStyle = .None
cell.configureCell(dishes[indexPath.row])
return cell
} else {
return UITableViewCell()
}
}
EDIT 2:
After further analysis, I am quite convinced that this has nothing to do with the height? I played around using different heights but still get the same results.
The thing is, it loads perfectly, even when scrolling down, it's all good. Up until I scroll back up, that's where the problem starts to appear.
Setting the Clip SubViews (Cell) to true will clip everything even on load, so I've set it to false.
The remaining question is, how to handle the clipping when scrolling back up?
EDIT 3:
I think I now understand the problem however, I am still not quite sure how to solve it.
The CircleView is placed on a cell that is meant to overlap to the other cell below it. Settings clipsToBounds, height or putting it infront will have no effect to the cell below it as it goes away from the display when scrolled up.
Anybody has an idea how to somehow redraw this just like it has been freshly loaded (because onload, things are working)? or perhaps is there a clipsToBounds setting elsewhere that I am missing?
I think the solution relates to this: How to stop UITableView from clipping UITableViewCell contents in iOS 7
However, this solution is not working on ios9.

Set the cell layer anchorPointZ to row index in cellForRowAtIndexPath: method
cell.layer.anchorPointZ = indexPath.row;

The issue has to do with the height of your cell. It isn't going to dynamically adjust that for you.
You can try setting the clips to bounds on the tableView (check screenshot)
clipsToBounds option

Have you tried setting an estimatedRowHeight for the tableView? Also, you can use the function heightForRowAtIndexPath and return UITableViewAutomaticDimension. That should automatically dimension every row to fill the circle size.
EDIT: If you want to bring the circle to the front of everything else, try this:
YourLabel.layer.zPosition = 1;
self.view.bringSubviewToFront(YourLabel);

Related

iPhone 6 Plus show strange lines in UITableViewCell next to the accessoryView

I have a UITableView that is showing some strange thin grey lines next to the accessory view. This ONLY happens on the plus, no other iPhone shows this issue.
It seems to have something to do with the imageView that is assigned to the cell. Some images cause the line, others don't, seemingly based on their dimensions.
Has anyone else seen this or know how to get rid of it?
I experienced this when using a UITableView that was partially covered with an SWRevealViewController.
When the calculated value of the tableview width was a decimal number, artifact lines between the content of a UITableViewCell and the accessory view would appear.
The solution was to make sure that size calculations for the view were rounded to whole numbers.
It looks like that line is from the right edge of the cell's content view. I don't know how it works, but my solution was:
cell.backgroundColor = .clear

Multilines UITextView inside a dynamic sizing UITableViewCell gets wrong

I'm doing an iOS 8 app, I have 3 UITableViewCell in a UITableView, and I need them to dynamic change their height. I implemented it using Autolayout and add 2 lines of code in the viewDidLoad method as below:
self.tableView.estimatedRowHeight = 66.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
It works!
But the issues appeared, There is a UITextView in the second UITableViewCell. Sometimes it can not display long texts entirely, but when I rotate the device/simulator to the landscape mode, texts display correctly and entirely. here it is:
Sorry for posting a screenshot that include Chinese, but you can check the last line of texts and notice the number with blue font. The last line appears in landscape but portrait.
However, I turn it back to portrait from landscape, the entire texts are displayed well as landscape:
Finally, there is another issue, the UITableViewCell list could get a wrong and overlapping layout sometimes as follows:
The cell with red line circled shouldn't be here!
Can anyone tell me what I'm doing wrong here?
Maybe it's hard to answer by looking these screenshots, so I posted the code file here
I guess these issues could be related with Autolayout constraints. But I'm not sure with this. Any help here? I'll be appreciated.
Thanks.

iOS8 tableviewcell height changing when rotating device in Swift

I am trying to use the new auto size for my tableview. Im doing this:
tableView.rowHeight = UITableViewAutomaticDimension
I have a multiline-uilabel in my UITableViewCell with some constraints that is working splendid; the height of the rows is dynamic when I enter the tableview in both landscape and portrait! Awesome!
... but when I rotate the device the rows get the basic height (i.e. 44).
I added this row:
override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval)
{
self.tableView.reloadData()
}
And the problem vanishes. But should this really be necessary? There must be a better way to fix this?
Edit:
I just found out that the same problem occurs when I'm deleting a row in the table view like this:
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
Am I missing something here? Why aint this working out of the box?
Edit again:
I've now doing like this:
self.tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
Then when my data is fetched from API:
self.tableView.reloadData()
self.tableView.beginUpdates()
self.tableView.endUpdates()
This seems to cover all cases I've tested so far, but it seems really hacky! Without the begin/end-updates the cells are displaying some really funky heights at the first load. (But when rotating the device, the cells adjust their heights correctly.)
This all just seems so buggy. I've not found a single guide which cover these cases correctly.
I had a similar issue with rotation where the entire searchbar and tableView were displaced-down on very rotation from portrait to landscape and back. See-> Swift searchBar separates from top of tableView after searchController.active during rotation:
Swift searchBar separates from top of tableView after searchController.active during rotation
I pasted your override function i.e.:
override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval)
{
self.tableView.reloadData()
}
after viewDidLoad function and my problem disappeared. Don't know why. Glenn Tisman
According to the WWDC session from this year, if the cell already uses Autolayout, then it is supposed to automatically resize for you. It would do this by trying to call systemLayoutSizeFittingSize:(CGSize), or if you have not used autolayout, it would try to call sizeThatFits:(CGSize)
On thing to make sure of if you're supporting iOS7 as well is that setting tableView.rowHeight and tableView.estimatedRowHeight will cause strange behavior, and you would want to conditionally call one or the other, but not both, depending on which version of iOS the app is running on.
If you're having issues with the label in particular, you might also check that you're using the new "Automatic Preferred Max Layout Width" attribute for the UILabel (if you're in a storyboard, this is under the "Attributes" inspector) and that lines is set to '0'. See the documentation for more detail. See also "Behavior of Labels" in the iOS Interface Catalog for some caveats about mixing certain behaviors of UILabel and getting strange results.
Finally, you might see what is happening in the newly added rotation methods for size classes:
-willTransitionToSize:withTransitionCoordinator:
-willTransitionToTraitCollection:withTransitionCoordinator:

Trying to make off-screen UICollectionViewCells pre-render using a custom layout

I have a paged UICollectionView, with one cell per page. However, my UICollectionViewCells are slow to render (third party library, no options there). So as an optimisation, i need to pre-render the cells to the left and right of the current page, so scrolling is smooth.
What i've done is, inside my custom UICollectionViewLayout, is outset the passed rect by 1 point before checking to see which cells' UICollectionViewLayoutAttributes should be returned, see here:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
CGRect outsetRect = CGRectInset(rect, -1, 0);
return [_myAttributes filter:^BOOL(UICollectionViewLayoutAttributes *attribs) {
return CGRectIntersectsRect(attribs.frame, outsetRect);
}];
}
This works as expected. However, when the actual UICollectionView does its thing, it seemingly ignores the offscreen cells and calls cellForItemAtIndexPath only for the first cell, not the cell to the right (or left).
Any ideas what is going on? Thanks
For future reference, i solved this by:
Making cells for pre-rendering forcibly moved on-screen a little, but with the same size.
Changing their z-index to -1 so they are under the main page cell.
In the layoutAttributesForElementsInRect, check if the rect is two pages wide, and if so then it's scrolling between pages, so don't grab any extra pages
In my cell's applyLayoutAttributes, i check if the z-index<0, and if so, then this is a pre-rendering cell.
Cheers

Is the separator part of a UITableViewCell?

I've written a custom GridView (UIScrollView Subclass) and decided to use a standard UITableViewCells as Cells because they have all the functionality I need.
Everything works fine but I've noticed that sometimes I have a thin gray line at the top of a cell.
I actually thought that the UITableView handles the separators of the cells and they actually don't belong to a UITableViewCell but it seems to be that I'm wrong.
In fact I want to get rid of them but I don't know how.
Does anyone has experience with this or is the only way to make a custom cell class with the features of a UITableViewCell?
Here's a screenshot:
After some experimentation, try & error and subview iterating/checking I can tell that the separator is definitely part of an UITableViewCell. Thanks to #Valeriy Van.
The answer to my first question simply is: YES, the separator is
part of a UITableViewCell.
But it is strictly handled by the UITableView and is empty if it is not populated by the TableView.
Now to the lines in the image above:
These are not separators. They just look like that, such a damn coincidence.
They happen when the Graphics tries to draw something at subpixel-precise coordinates.
This can happen, when the coordinates and/or sizes (the frame) of an visible object (the layer of the view) are between two integer values and the GL tries to render it properly.
Due the "overprecise" frame, the Gl tries to interpolate to integer frames or just not round properly.
So it can happen, like in the picture above, that the first line is stretched or the y-coordinate wrong by one pixel.
This can also happen in a UITableView if you return "overprecise" values for cell-heights.
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Edited:
Below is a line from UITableView.h
#property(nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine
UITableViewCell, UITableView, UITableViewController designed to work together. And your problem is you try to use UITableViewCell separately. Logically, cells separator is not characteristic of a cell, it's characteristic of a table. That's why separatorStyle is property of UITableView, not UITableViewCell. Well, different approaches are possible, and Apple had chosen this. Look into UITableView.h for how many times 'separator' substring occurs there. Have a look into UITableViewCell.h: UITableViewCell has reference to UITableView. And UITableViewCell coded accurately enough not to crash if _tableView is nil. I think, if _tableView is nil, cell applies same defaults and draws itself with default separator.
What can you do to get rid of separator in you case? If you can't use UITableView in way it was designed, cheat in some way. Try to feed cell with some dumb tableview with properties you need.

Resources