Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Protocol Not Implemented"

When I make a new controller called TestController, I insert

<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UISearchBarDelegate>

to the interface of Test.h

When I run the app on the simulator, there are many issues that say "incomplete implementation" and "method in protocol not implemented"

I know some method is not implemented, but which one? How do I know what method I should add?

like image 353
user4951 Avatar asked Sep 11 '25 08:09

user4951


2 Answers

Show the issues navigator and expand one of the "method in protocol not implemented" issues. The first detail item will show you where the method is defined in the headers (and, thus, which @protocol it's in). Even better, though, the second detail will show you the name of the protocol.

Switch to the Issues navigator. Ignore the Incomplete implementation message, and look at the Method in protocol not implemented message. You can expand this message to get more information that the compiler provided. The first detail is what you're looking for:

Method declared here

You can see here that I've forgotten to include a method for tableView:numberOfRowsInSection:. I can copy this declaration and paste it into my own code to start writing the method.

Note that there are three issues in my issue navigator. The third is another missing method, which can also be expanded and copied in the same way.

like image 87
Steven Fisher Avatar answered Sep 12 '25 23:09

Steven Fisher


There are two things I can think of which you can look for. First, look in your .h file and see if you have any method prototypes that you may have forgotten to implement, or else implemented and then changed the implementation such that it no longer matched the prototype's method signature.

Second, if the compiler isn't telling you which methods are missing, look at the documentation of UITableViewDelegate, UITableViewDataSource, etc. In the Tasks section, where it lists the various public class and instance methods, it will say "required method" next to any that need to be there. For example, if you class conforms to the UITableViewDataSource delegate protocol, -tableView:cellForRowAtIndexPath: and -tableView:numberOfRowsInSection: are required.

like image 43
Zev Eisenberg Avatar answered Sep 12 '25 23:09

Zev Eisenberg