Accessibility not working properly on UICollectionView inside UITableViewCell - ios

in my app i have a UICollectionView and UIPageControl inside UITableViewCell. UICollectionView has three different kind of cells and each cell covers the full width of iPhone. With accessibility on we are facing a problem when the focus is on UIPageControl and we try to adjust its value by swiping up and down and then traverse back to the cell it loses its focus and takes us to some different cell instead of taking control to the cell which we have changed using UIPageControl.
We are changing the cell on value change event of UIPageControl.

Related

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.

Only first collectionViewCell reacts to user interactions

The setup
I have a rather complex view hierarchy which made me do terrible things with tableViews and collectionViews. Right now I'm having a regular grouped TableView with custom TableCells. TableCell itself contains a couple of views and a Collection View. The height of the table cell is calculated based on number of items in the data source. On its creation table cell creates a collection view with a calculated size to fit necessary data.
-- UITableView
---- UITableViewCell
------ UICollectionView
--------- UICollectionViewCell
The problem
I've encountered unusual problem with a custom collectionViewCell. I have a vertical single-column collectionView with dynamic amount of cells. Ideally tapping on the cell should call didSelectItemAt. The cell also has three buttons. Tapping on the button should trigger some action. All of the desired functions work only for a first cell. The rest of the cells are not responsive to any actions.
Things that look strange
By default the scrolling of a collectionView inside of the tableViewCell is disabled because it basically fits all the content based on calculated height and doesn't require scrolling. (Also I don't want it to interfere with tableView scrolling logic).
First
I've tried to hardcode some value for the height of collectionView and enable scrolling. What happened is a mystery for me.
Let's say that calculated height required for the collectionView to show all the content without scrolling is 740. When I manually set it to be 280 (this is enough for exactly 2 cells to fit) and enabled scrolling my first cell were still working, but also when I scrolled collection just a little bit my second cell started to act normally as well. When I scrolled back to the top of the collectionView it was disabled once again.
So it looks like when the scrolling is enabled and will actually occur because of insufficient height to fit the content, cells behave as they should. As soon as I set height of the collectionView to be enough to fit its content, things go wrong.
Second
In some cases I can actually tap on the second cell and it will call the delegate. But the weird thing is it works when I tap in the top area of the cell, like 10pts from the top. The other areas of the cell are unresponsive so are the rest of the cells in the collection.
The working delegates and buttons with enabled scrolling forces to think that this has nothing to do with delayed or canceled touches. The frame for collectionView and height of the table cell are calculated properly as well.
xCode 8.3, iOS9+
As it turned out when I was creating my tableViewCell, I hardcoded the height of the collection to value of 214. The reason for that is very simple. I create a cell programmatically and with tableViewCells created programmatically the height of the cell is always 44. When you override init(style: UITableViewCellStyle, reuseIdentifier: String?)
You need to either hardcore the height, or update it in cellForRowAtIndexPath. Even though I updated collection frame when it was filled with data, the container view of this collection wasn't updated resulting in some sort of clipping area for user interactions.

Incorrectly positioned UITableViewCell when containing UITextField

I've created a simple project. It contains a UITableViewController with self-sizing prototype cells that contain a UITextField and a UILabel for displaying validation message. The controls are grouped in a UIStackView, but that doesn't seem to matter.
The label is only visible if there is a message to display, otherwise it's size collapses to 0. To adjust the size of the cell I simple call the recommended:
tableView.beginUpdates()
tableView.endUpdates()
If I scroll the view with the UITextfield remaining first responder (ie w/o dismissing the keyboard), so that the cell is no longer visible, when scrolling back to the cell, it is misaligned.
I've hosted the sample project at https://github.com/ionel71089/tableViewTextField
Note:
Easiest way to reproduce is on Simulator iPhone 6 9.2, by editing let's say the 50th cell, scrolling to the top and then back to the cell.

UIScrollView in Custom UITableViewCell mixing up data

I have a UIScrollView in each UITableViewCell of my table view that lays out UIViews horizontally - kind of like the "Featured" section on Apple's App Store. When I'm setting up the UITableViewCell I call a function within the custom UITableViewCell to layout the scroll view. This loops through data assigned to that tableview cell's index path and then creates the custom views and adds them to the scroll view. However, these get mixed up when scrolling the tableview and when the tableview refreshes.
If I clear the subviews before laying them out, it does work. However, I'd like to keep the scroll position at the same point every time it shows the cells. How is this possible?
I've just added an external array that stores the current offset for each scrollview, and then manually set the offset on each scrollview everytime the tableview gets refreshed.

How to scroll or prevent scrolling in UICollectionView using swift?

I have a UICollectionView with one section, 10 cells and horizontal scrolling using a Flow Layout.
One cell occupies the entire screen, and has a UITextView and two UIButtons.
How can I prevent scrolling if no button in the cell is selected, and if it is selected, how can I scroll to the next cell on a UIBarButton click?
I would also like to preserve selection in order to be able to go back to the previous cell and change the selection if needed.

Resources