UITableViewDataSource and UITableViewDelegate protocols


We’ve implemented two methods in ItemsViewController.m that are required by UITableViewDataSource protocol, but that protocol hasn’t been declared anywhere. Either has UITableViewDelegate protocol - why?


A class conforms to a protocol if the protocol is named in between < and > right after the inheritance relationship in the header file.
For example:

@interface MyClass : NSObject <UITableViewDataSourceProtocol>

Therefore you don’t need to declare the names of the methods anywhere.
You can find out more about specific protocols in Apple Reference:
developer.apple.com/library/ios/ … rence.html



I may not have been very clear in my original post, but that is my point. The protocols haven’t been named in the header file (ItemsViewController.h). I checked the source code from BNR and they’re not named there either. However, my code compiles and runs fine.


Ah…I see your point.
You are not “forced” to declare your methods in the header file. You can leave out the declaration - for example to keep that method “secret”.
You can download a little project showing you your options and the consequences of not declaring a method from my dropbox: db.tt/UPfGXaRW

By the way if you try to set a class not officially conforming to the needed protocol as delegate, you will get a warning.