UICollectionView selection/deselection methods not triggering - uicollectionview

Basically I have a UIPageViewController which has multiple UICollectionView on each pages.
The problem is I can select/deselect on collectionViews inside the first page. But when I switch to second page, numberOfSections, numberOfItemsInSection, cellForItemAt are all called however the selection and deselection delegate methods are not called at all.
here is the link to the code:
https://gist.github.com/anonymous/4eca4ff9f3e4423c01974609aeae5482

I can't connect to your link. But you must make sure delegate of UICollectionView was set and check allowsMultipleSelection and allowsSelection is YES. You can reference links below:
UICollectionView - didDeselectItemAtIndexPath not called if cell is selected
iOS: UICollectionView cell selection not working

Related

Accessibility: didSelectRowAtIndexPath not called when cell selected with voiceover

I have a very simple UITableView with a custom class for my cells. The cells consist of various labels (isAccessibility=NO).
I have an accessibilityValue set for each cell, and isAccessibility=YES/enabled in Storyboard for each cell.
When the user double-taps to select the cell...nothing happens. didSelectRowAtIndexPath, which contains my navigation logic, does not get called. At other locations in my app that use segues work fine, with the same cell setup.
What am I doing wrong that would make didSelectRowAtIndexPath not get called?
Edit: this code works fine without Voiceover. Tapping the cell calls didSelectRowAtIndexPath as expected. Voiceover simply isn't triggering didSelectRowAtIndexPath.
I have got the same problem.
Fix below work for me
cell.isAccessibilityElement = YES;

focus on UITextField inside a UICollectionViewCell

I have created a custom UICollectionViewCell that contains a UITextField inside of it which is only accessible when the cell is selected. The CollectionView has multi select enabled and the problem is that when trying to select the UITextField to type in it, the cell is deselected instead of giving the TextField focus.
How do I allow focus on the UITextField inside of the CollectionViewCell without causing the cell to be deselected?
Note: I've also tried adding buttons to the cell template and the button actions are not getting called either. It seems as though the cell itself is capturing all of the touch events and not passing them along to child views.
I'm not sure what the original problem was, but I solved it by re-creating the UICollectionViewCell interface inside the UICollectionView in my storyboard instead of loading it from a different .xib file.

UITableViewCell setEditing is not called

I have UIViewController that contains UITableView. I implemented my custom edit button that toggles setEditing:animated for the table view. Everything works good, delete and reordering icons show up. Table view cells has custom class (subclass of UITableViewCell), where I override setEditing method to do some extra customisation when edit mode is ON.
From documentation:
When the table view receives setEditing:animated:, it sends the same
message to the UITableViewCell object for each visible row.
As I understand setEditing method should be called for every cell, but unfortunately it does not happen. Where could be the problem? What I am missing?
I found my mistake. I was overriding
-(void)setEditing:(BOOL)editing
but instead I should override
-(void)setEditing:(BOOL)editing animated:(BOOL)animated

Receiving notification on a UICollectionViewCell's (or UITableViewCell's) removal from its parent collection or table view

Background:
I have a UICollectionViewController that shows items in one of two modes, which the user can toggle between. Each mode uses a different class of UICollectionViewCell. Let's call these modes "list view" and "grid view".
When I switch modes, I call .reloadData on the UICollectionView, which redraws the collection view using the correct cell classes. Everything works fine here.
Now: Inside the UICollectionViewCell subclass for one type of cells, I want to be notified when the collection view that contains it switches modes. Visually, a cell which was on-screen vanishes; the collection view is drawn fully with the other type of cell. When switching back, the cell is re-displayed.
Question:
How can I be notified when a UICollectionViewCell is "removed" (i.e., no longer shown; I'm not sure what's happening under the hood yet) from its parent collection view?
Notes:
prepareForReuse is not called on the cell when the collection view's updateData causes the cell to no longer be included.
willTransitionFromLayout:toLayout: (an empty layout?) is not called.
Overriding didMoveToSuperview is of no help; it is not called.
Observing .hidden or .alpha on the cell does not work.
The cell's dealloc is not called; it sticks around in the reuse queue.
Something in the cell must be changing that I can observe or hook into, what is it?
Update: UICollectionViewDelegate has this method, which from the documentation seems like it does what I am asking:
collectionView:didEndDisplayingCell:forItemAtIndexPath:
Original answer:
I got this working as desired by having the UICollectionViewController manually notify visible cells of impending doom with this method when I'm about to toggle and call reloadData:
- (void)notifyCellsWillBeHidden {
for (UICollectionViewCell *cell in self.collectionView.visibleCells) {
if ([cell respondsToSelector:#selector(willBeRemovedFromCollectionView)]) {
[cell performSelector:#selector(willBeRemovedFromCollectionView)];
}
}
}
These cells can then do what they need to do if they implement the above method.
Calling prepareForReuse may not a good idea because it will be called again before the cells are re-displayed, if this is a problem.
I'm still curious whether there is a way for a cell to receive notification that it is going to be made non-visible without an explicit call.

Drawing table view cell when drag and drop

I have dragged an item into my tableview object.
When the dragged item hover over an item in tableview,
the item is redrawn with selection background. The image is as under
The row of the tableview is not selected, when i checked selectedRow method.
My requirement is when an item hover any item i should control its selection
and the background selection thereof.
Thanks,
iSight
To 'control' the selection of a TableViewCell when 'hovering' over such an item you will have to call this method:
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
It's a method from the UITableView Class and uses the local coordinate system of your tableView. As is mentioned in the Apple Doc: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html
When the method is called you will have a NSIndexPath returned. With it you can select the cell/item at that particular path.
Mind, selecting a path manually doesn't call the didSelectRowAtIndexPath delegate-method so if you want a certain method called from that delegate you will have to do that manually as well!
This method is prolly called from the touchedDidMove method (where you also do the drag&drop) so getting the point needed for the method shouldn't be a problem for you.
You will figure it out :)
Good luck.