Subviews of UITableViewCell are not visible while reordering - ios

When I reorder my UITableViewCells, the Subviews of the Cell are not visible while dragging...I get always the same result, whether I add the Subviews programmatically in a UITableViewCell Subclass or in Storyboard...
Is there a possibility to see the real UITableViewCell with Subviews while dragging?

Ok I found a solution by my self...
For some reason the mysterious reordering animation from Apple cant capture simple UIViews, but with UIImageViews, UIButtons and UILabels as Subviews of the custom TableViewCell, the animation works like expected...creepy!

Related

Unwanted UIView over UICollectionViewCell (TapGesture Doesn't work )

Recently, I see a strange thing in Xcode 11.4.
When I create a UICollectionView with Its cell, adding TapGesture doesn't work. By debugging on its view in runtime, I noticed a view covers all the cells. It seems it is ContainerView.
This view prevents users to click or tap on items.
Any help is appreciated
Are you adding your subviews and tap gesture to the cell's contentView?
In the documentation for UICollectionViewCell (https://developer.apple.com/documentation/uikit/uicollectionviewcell), it says:
To configure the appearance of your cell, add the views needed to
present the data item’s content as subviews to the view in the
contentView property. Do not directly add subviews to the cell itself.
The same applies for UITableViewCell as well.

dynamic, custom layout UICollectionView embedded in UITableViewCell

I have UITableViewController with 1 section and header with UISegmentedControl inside.
If user presses first segment we should display UITableView cells
If user presses second segment we should display custom vertical scrolling collection grid with collection items below that header
possible solutions:
change UITableViewController to UICollectionViewController, and UITableViewCells to UICollectionViewCells. This should work but I'm trying to avoid this solution
UICollectionView embedded in UITableViewCell. Setting UICollectionView scrolling enabled to false, adjusting UITableViewCell's height to fit entire UICollectionView's contentSize.height. In systemLayoutSizeFitting(...) method of container (UITableViewCell) we call layoutIfNeeded on container and on contained UICollectionView and return UICollectionView's contentSize.
problem:
(re)calculation of entire UICollectionView contentSize requires a lot of work if we have hundreds of items (cellForItemAtIndexPath for every item). Want to avoid this somehow. Maybe we can increase container (UITableViewCell) height during scrolling UICollectionView which is embedded inside.
Same as 2 but we have fixed size container UITableViewCell (same height as view without header) with UICollectionView inside. When we scroll UITableView to the very bottom UICollectionView scroll should continue scrolling.
problem:
I don't understand how to deal with 2 instances of UIScrollView with scrollingEnabled = true for both. I think this could be solved with pan gesture recognizer delegates. If it is so I need help here.
I would personally opt for number 1 and completely avoid number 2. For number 3, you could set tableView.scrollingEnabled = false when the second segment is tapped. Set it to true when the first segment is tapped. That way, when it's false, the UICollectionView in your UITableViewCell can still scroll.
This tutorial may help with putting a UICollectionView in a UITableViewCell.

How to preLoad UICollectionVewCell?

I have all the UICollectionView dataSource, but the subViews in cell is not all the same.So need remove the old subViews and add the subViews when the cell showing again. Want to know any way to preload UICollectionViewCell or Make it more smoothly.
Instead of "preloading" the cells, I would suggest subclassing UITableViewCell for each of your different types of cells, and adding the subviews in their awakeFromNib method. I would recommend against adding subviews in your tableview:cellForRowAtIndexPath: method, you should just be updating the content (e.g. UILabel values).
If you add subviews inside tableView:cellForRowAtIndexPath" method, you will need to remove all of the subviews first. Otherwise if they are "reused" the subviews will be added on top of the existing ones.

New UITableViewCell not calling subview drawRect()

I am having this problem for the past two days and I'm trying to get my head around it with no good result.
I have a UITableView with custom UITableViewCell. Inside the UITableViewCell I have a custom UIView that I subclassed and drawing it by calling its own drawRect.
The drawing for reused cells has no issues and the cell is calling its own drawRect and the custom subview is calling its own drawRect as well.
The problem arises when a new cell is dequeued, the custom subview drawRect is not called at all leaving that view empty (non visible)
What I did:
calling subview.setNeedsDisplay has no effect, it's redrawing the reused cells' custom subview but it has no affect on drawing the newer cells' custom subviews.
That's the only thing I thought of and was obvious to try.
Is there a way to force drawing for the subviews for new UItableViewCell?
Have you tried calling [cell setNeedsDisplay] but on the main thread?
I managed to solve the issue and force the redrawing of the subview of a custom cell by implementing heightForRowAtIndexPath regardless of the iOS version (>=7)
Apparently iOS redraw the cell after the height is being calculated.

UIScrollView within UICollectionViewCell Not Working

I have a UICollectionView with a custom UICollectionViewCell. The UICollectionView scrolls horizontally, with each cell occupying all of the visible screen.
The UICollectionViewCell has a UIView subview, which in turn has a UIScrollView subview.
The UIScrollView is intended to scroll vertically, but it's not scrolling at all. I've tried setting the scroll view's contentSize with no success.
I suspect that the UIScrollView is not getting any touch events rather than it being a size issue.
Any suggestions?
EDIT >>
I'm now sure it's an event problem rather than anything specific to the UIScrollView.
I've now overridden the pointInside: method in the UIView in the UICollectionViewCell and can see that it now returns false every time I tap on it. In that case you'd think that the tap event would propagate to the next subview , but the UIView still isn't getting events. I've tried adding a UIGestureRecognizer to the UIView but it never registers a tap.
Could there be anything here intercepting the events that I'm not aware of?
I've been trying to solve a similar problem with a scrollview, and your edit about events reminded me of this question (which solved my problem again) How can I use a UIButton in a UICollection supplementary view?
Its possible you need to be using a UICollectionReusableView, not a UICollectionViewCell. Changing the class worked for me because I was using a button (and recently a scrollview) in a header.
However I've not tried for cells themselves. For capturing events from a UICollectionViewCell, maybe the following may help?
Getting button action : UICollectionView Cell
Try to disable userInteractionEnabled for the UIView and enable it for your UIScrollView
I'm not sure if this was your problem, but it was mine - and I'm putting it here in case anyone else comes across this for the same reason. I wanted to put a UIScrollView inside a UICollectionReusableView but by accident I had created my custom class as;
class CustomCellHeader: UICollectionViewCell {
}
instead of;
class CustomCellHeader: UICollectionReusableView {
}
Once I changed that, the UIScrollView within my header cell came to life!
Embed the scrollable content in a ScrollView within the cell.
Add "UICollectionViewDelegateFlowLayout" to the UICollectionViewCell i.e.:
class SomeCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout {
}
Now scrolling within the cell should work.

Resources