UICollectionView doesn't call delegate methods - ios

I've setup a UICollectionView in a storyboard and connected the dataSource and delegate outlets. I've registered a cell via nib which I dequeue in the cellForItemAtIndexPath: method.
All works perfectly expect that the delegate methods are never called. For example: When touching on a cell, I expect the didSelectItemAtIndexPath: to be called.
I've double-checked the delegate of the collection view - it's assigned correctly.
Does anybody know the reason why the methods are not called?

It's completely my fault. I've added a transparent subview to the front which consumes the touches - a really bad mistake.

Related

Table View's Delegate Method Cell for row at not called

I am using a table view and set the delegate and datasource in view will appear.
return 1 in number of section and 5 in number of rows but cell for row at delegate method is not called. I checked my storyboard view cell's ideantifier and class name is correct. Pls help
There are few things that may be or are wrong with your code. First one is that you should setup the delegate in storyboard or ViewDidLoad (in storyboard drag from tableView to the ViewController instance and select both - delegate and datasource) The other thing is that you may made a typo when writing the code for delegate methods(always use automatic method completion feature in xcode)
After setting delegate and datasource , reload the table view.

Get indexPath of UICollectionViewCell

I have a custom CollectionViewCell class, I have then generated an amount of these inside of a CollectionView. I have then also added a modal segue when the ViewCells are touched. How would I get the id (or index path) of which cell was pressed when the modal segue is activated.
I saw on here that someone suggested I add into the ViewCell.m file the method
-(void)collectionView: (UICollectionView*)collectionView didSelectItemAtIndexPath: (NSIndexPath*)indexPath{
//get indexpath variable in here
}
But this method does not seem to be getting called. Can anyone help me with what method would need to be get called for when a CollectionViewCell has a modal segue to get the indexpath.
Thanks,
If the views you have added to your cells are handling the touch by firing a segue, then the collectionViewCell never has a chance to receive the touch.
If you want the collectionViewCell to handle it, make the subviews of your cell purely decorative by disabling their behavior to fire the segue. (for example, if they are buttons and "touchUpInside" fires the segue, then change them into views with no touch handling at all.).
Then the touch will be passed up through the view hierarchy until the CollectionViewCell handles it, which it does with the collectionView:didSelectItemAtIndexPath: method.
The method is a callback of the delegate class of the collection view object:
-(void)collectionView: (UICollectionView*)collectionView didSelectItemAtIndexPath: (NSIndexPath*)indexPath
So you should implement on the .m file of the delegate class of you collection view.

UITableView delegate methods being called before viewDidLoad

I have a view controller that subclasses UITableViewController. When I push this VC onto the navigation stack, the UITableView delegate methods get called, then viewDidLoad gets called, then the delegate methods get called again. What is going on here?
Because your view is a subclass of UITableViewController, the delegate and datasource are attached from the very first moment it's created, and the methods are called as soon as the datasource is asigned.
Also, you can set a breakpoint on it and see which class called the datasource.

UITableViewDataSource responds, but delegate doesn't

I have a tableview in a nib file, that has the datasource and delegate set to file's owner. It also has an outlet set to an IBOutlet property declared in the class. All of the datasource methods responds as one would expect. None of the delegate methods respond.
I have gone through everything I can think of so far: deleting the tableview, adding another, clicking and unclicking the datasource and delegate connections, you name it. Always the same.
I have a tap gesture recognizer on the main view, and the delegate set to self. So when a tap comes in, I'm able to intercept it in the gesture recognizer delegate method, and the tap is indeed coming from a table view cell. This is recognized as a tap from within the table, and so the method returns NO to tell the gesture recognizer not to respond.
Any thoughts?
Well, we tried everything. Shutting down Xcode, blowing the environment away and re-checking out the code, shutting down the machine, nothing.
Copied those files to another machine, and it works.
Clueless...

iOS TableViewCell lifecycle - set outlets

What TablleViewCell method is called once the outlets of a custom TableViewCell are set when the TableViewCell is instantiated from a storyboard? So a method similar to viewDidLoad essentially. I tried awakeFromNib but it appears that outlets aren't set there as I would expect.
It seems that
layoutSubviews
does the trick.

Resources