UITableViewDataSource responds, but delegate doesn't - ios

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...

Related

Modifying the scroll view function scrollViewDidEndScrollingAnimation

I wanted to override the function scrollViewDidEndScrollingAnimation for a reference to a tableView within a class.
In other words, I have a view and a UITableView within it, I dragged a reference to the table into the view controller and want to change the scrollViewDidEndScrollingAnimation for the same, is it possible to do so?
I have looked at previous responses to similar questions and they ask suggest making the class a scrollViewDelegate and implementing the function, but I have done so and it doesn't hit the breakpoint I have within the function even if I scroll through the table in the Simulator.
This method only gets called if the setContentOffset:animated: or scrollRectToVisible:animated: methods are called by you on the scrollView, and only if the animated parameter is set to true.
Scrolling the view in the simulator will not trigger the breakpoint in your implementation, but using either of those two methods will.
UIScrollViewDelegate Protocol Reference

tableView delegate and datasource

I'm learning Swift. Sometimes I see that Main.Storyboard is used to set up the tableView delegate and dataSource (ctrl+click and so on). Sometimes I see that it's done through coding instead like so:
// create the variable for the tableview
IBOutlet weak var someTableView : UITableView!
// setup delegate and datasource
sefl.someTableView.delegate = self
self.someTableView.datasource = self
I do understand how it works with second way. But it's difficult to realize how it works through Main.Storyboard with no IBOutlet setup.
Thank you for your responses!
It works exactly the same way :)
Let me refresh the principle:
You have a class, provided by Apple in this case, that has to work for a lot of scenario. Apple decided to use a kind of inversion of control, called delegation, where the workflow is inverted (hence the name) : instead of the view controller giving order to the tableView by calling methods on it, it is the tableView that goes and fetch its orders from the controller by calling methods on it.
In order to achieve this kind of IoC (inversion of control), the TableView MUST know the "address" of the object it has to ask for its order. Like you have to know your boss' email address to ask him stuff. So, the UITableView class as a property called dataSource that means to store that address.
Now as a ViewController programmer, you have to set this property to be the address of the view controller that will give the order to that tableview.
2 ways of doing it :
in code : in the view controller, you have a property pointing to the tableview (if linked from the storyboard, it is called indeed an IBOutlet, but doesn't have to be) and you set it's delegate property to self. (meaning 'hey tableView, your boss is myself)
Or you do it in the storyboard, because the graphic template for the tableView let you ctrl+drag from the tableView to the ViewController and set the datasource connection. In this case it will be the storyboard who will have to find the address of the tableView (since it is the one creating it, it's kinda easy) and setting it's delegate property to be the address of the view controller (meaning hey tableView, your boss will be this guy)
Either way, the viewController has to be ready to answer all the question from the TableView, so conforming to the UITableViewDataSource protocol.
the delegate scenario is the same.
It is important to understand how the loading of views works in iOS. Your xib will be translated into the hierarchy of views and they are loaded onto the memory. When you make an IBOutlet of those views, you'll have a reference of that loaded view in your code. If you do not create an IBOutlet, it doesn't mean that the view isn't there. It is there and it is in the memory.
When you set the delegate and the dataSource of a tableView and when the tableView is loaded onto the memory, it sets the delegate and the dataSource of the loaded tableView to the class as specified by you. It doesn't matter if you do not have a reference to it.

mapView:viewForAnnotation: not called in iOS6, works fine in iOS7

I need to show a blue point (current user location) on my map. It's a trivial task, on my device with iOS7 it works ok, on another device with iOS6 it doesn't. I set map view's delegate from .xib, also my map is connected with controller through an outlet and I do not init/alloc this property in controller (I saw a lot of guys doing this). One more thing to notice is that regionDidChangeAnimated is called ok, and it's one of map view's delegate methods. I don't have idea why this happens.
There is a bug in IOS6, if you are added the mapView:viewForAnnotation: after setting the delegate, then this delegate method will not be invoked. MapView will be use a default annotation view in this case. So try to remove your delegate connection from outlet and set the connection after a cleaning.

GestureRecognizer and IBOutlet don't work together

I'm creating an iPhone app. In my main view, I have a subview. When I add a gesture recognizer to this subview, and I connect it to an action in my view controller, it works : the action method is called when the gesture is performed.
But when I connect my subview to an outlet in my view controller, suddenly, the gesture recognizer doesn't work anymore.
I have recreated this simple situation in a blank project, and here it works... Have you an idea about the origin of my problem please ?
So after reading your comment, I understand that the problem was indeed that you "messed" with the IBOutlet instance in your viewDidLoad as I presumed.

UICollectionView doesn't call delegate methods

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.

Resources