I have a UICollectionView that displays cells that can have multiple types of content. The content could be a view, a scrollview, a button, etc. For the most part, the table is displaying correctly, but touch events to not appear to be getting passed down to the cell contents. (Buttons aren't accepting clicks, scrollviews aren't scrolling).
Is there a way to pass the touch events to the contents on each cell?
Are you loading the UICollectionViewCell from nib? The elements in the nib are not added to the UICollectionViewCell's contentView and thus the events are not going through to cell contents.
I had the same problem wit a cell loaded from nib including a UITableView and I was able to fix it by manually adding the table to contentView like this:
[self.contentView addSubview:_tableView];
I found the fix here.
Related
I sub-classed UIcollectionViewLayout to create my own layout. In the prepareLayout() method I create the frames for the attributes of each cell because I know where they should be. The frames for each cell are hardcoded. However, I can't hard-code the position of the frames because I want to be able to drag and drop cells. UICollectionViews have nice functions for that:
`collectionView.updateInteractiveMovementTargetPosition(_:position)`.
But this function can't change the location of the cells if their position is hard-coded.
Additionally if the cell is not in it's position it seems to disappear from the view. I want to dynamically change the position of a cell when I begin to drag it. Should I call invalidateLayout() somewhere? I have a UICollectionView as a subview of my UIViewcontroller.
So I've attached a longPress gesture recognizer to my collection view.
I faced this issue few months ago, you cant reload selected cells, the only way is reload whole Collection View. If you have any other solution, pls share me. Thanks
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.
I initially load a hidden tableView with some data and show this when I press a button, simulating a drop down menu.
In the same view, I have a UIButton which when pressed, programmatically creates another UIButton and a UITextField.
The problem is that when I load again, the tableView and all the textFields and buttons are superposed.
This is what happens:
My question is what can I do for keep the tableView in front of in the view.
When you do -addSubview:, the view is added as the top-most view.
Which is the reason why your newly added textFields are appearing above your tableView.
The quickest way to solve your issue would be to make the tableView the top-most view when you're planning to show it.
Example:
[yourTableView setHidden:NO];
[self.view bringSubviewToFront:yourTableView];
Assuming that self.view contains yourTableView
What you are experiencing is a cell reusability issue.
If you are adding controls on cells, when they get reused They will keep the textFields which gives you this strange juxtaposition result.
You have to take proper care of removing the textField which makes things more complex.
Solution is to subclass UITableViewCell so that you have prototype cell with textfield and another one without.
I have a UITableView that I've created in a UIStoryboard. It contains one Prototype UITableViewCell. The cells are populated in the ViewController's cellForRowAtIndexPath: method.
I'm now trying to add the ability to delete cells using commitEditingStyle:forRowAtIndexPath:. Everything is working except that when the delete button animates over the cell, the rest of the content doesn't shift over and it looks really ugly. According to this SO question, content will only be shifted if it's added to the cell's contentView rather than to the cell itself.
As such, is there a way to add a UIView (Ex. a UIButton) to a UITableViewCell's contentView within a UIStoryboard?
I have a view controller with following layout:
Container View
UIScrollView
UITableView as a sub view of a UIScrollView
I have another UITableViewController in which I have a few rows and some methods when the row gets selected. Now I want to display this UITableview inside the UIScrollView. So I add the UITableView as a subview of UIScrollView. The table is displayed in the scroll view just fine, but when I tap in the scroll view to select the table's row, then row is being highlighted but the method is not getting called when the row is selected..
PBDashboardPickupTable *dashtable = [[PBDashboardPickupTable alloc]initWithNibName:#"PBDashboardPickupTable" bundle:nil];
[self.scrollView addSubview:dashtable.tableView];
Also I have set scroll view's delayContentTouches to YES and cancelContentTouch to NO from Interface Builder. Also userInteractionEnabled is set to YES... then why is the method not getting called when I tap the table view's row?
Apple specifically warns in the documentation to avoid putting a UITableView inside of a UIScrollView:
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Since UITableView inherits from UIScrollView, I would suggest you add any additional views you need as a tableHeaderView, tableFooterView, or as custom cells in the table.