0

I have changed one of my instance methods to a class method so that it can be accessed from another class. The method is successfully called, but I have one warning on my code:

  • Incomplete implementation (on the line '@implementation myViewController')

My class code looks like this:

//...

@implementation myViewController

#pragma mark - myMethod
+ (void)myMethod:(CustomUIView *)customView didSelectText:(NSString *)text
{
    //...
}

//...

In my class header file, I have the following:

#import "CustomUIView.h"

//...

@interface myViewController : CustomUIViewController <CustomUIViewDelegate>
{
    //...
}

//...

@end

I imagine I must be declaring the method in the wrong part of the header file, possibly due to the clause? Or I'm missing something else altogether. I've had a good look around the net and as far as I can tell I'm following protocol; perhaps there's something peculiar to my setup?

Edit: This is my protocol from my CustomUIView header file:

@class CustomUIView;

@protocol CustomUIViewDelegate <NSObject>

+ (void)myMethod:(CustomUIView *)customView didSelectText:(NSString *)text;
//...
@end
CaptainProg
  • 5,610
  • 23
  • 71
  • 116
  • Where's your implementation of TSAlertView? – Hot Licks Nov 04 '12 at 12:44
  • @HotLicks Had meant to change that to the generic 'myMethod'; hopefully the question makes more sense now. – CaptainProg Nov 04 '12 at 13:44
  • If `CustomUIViewDelegate` says that `myMethod:` is an instance method, then a class method won't be seen as a match. (Perhaps add the protocol definition to your question.) – Phillip Mills Nov 04 '12 at 13:52
  • @PhillipMills my code directs to the right place - the method is found. The only problem is that I have these warnings in my code... – CaptainProg Nov 04 '12 at 13:54
  • @CaptainProg ...which is why I said "won't be **seen** as a match". If the compiler sees what it thinks is a required method in a protocol, it complains when it's not implemented. If you don't actually call that method then nothing will trigger a run-time error. – Phillip Mills Nov 04 '12 at 13:56
  • I've updated my question to include the protocol definition, hopefully this will make things a little clearer? – CaptainProg Nov 04 '12 at 14:03
  • The message is "myMethod in protocol not implemented"??? If so, where is the protocol that's declaring myMethod? – Hot Licks Nov 04 '12 at 14:06
  • I have simplified the question and corrected all syntax issues suggested thus far. However, the problem remains the same. The question has been updated to reflect the current state of play. – CaptainProg Nov 04 '12 at 14:25

2 Answers2

1

Your mistake is in the name of the method. Implementation is didSelectText and interface is didSelectTerm. (Text vs Term -> obviously should be the same) Also, you call [[self class] otherMethod:text]; as a class method, which, if you look closely, is not.

Rad'Val
  • 8,895
  • 9
  • 62
  • 92
0

Your changes don't make sense.

You can access instance methods from other classes - they don't have to be class methods. Class methods means they are methods that are implemented by the class - not an instance of the class.

Secondly, within your new class method, you are calling a method (otherMethod:) which as an instance method, i.e. one that is called by an object of the class. Since you are calling it at [[self Class] otherMethod:text] this is wrong as [self Class] is used to call class methods, not instance methods. You don't have a valid reference to an object of your class to send the message to.

To add:

You've implemented a method:

+ (void)myMethod:(CustomUIView *)customView didSelectTerm:(NSString *)text;

but your protocol expects:

+ (void)termTextClickedOn:(TSAlertView *)customView didSelectTerm:(NSString *)term;

The names you give your actual parameters don't matter so the difference in text and term don't count, but the method names, as written in Objective-C boil down to:

+ myMethod:didSelectTerm:

and

+ termTextClickedOn:didSelectTerm:

Not only are the two names different, but the types of the first parameters are different as well, one takes a CustomUIView *, the other takes a TSAlertView *, which might work if one is a subclass of the other, but in any case, your method names are wrong.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • now that you edit the answer, you got it right, wanted to edit my comment, but I was not able so I added another one to emphasise that – Rad'Val Nov 04 '12 at 14:19
  • My apologies, I have been changing my method names to make my question a little more readable. In the first edit, I forgot to adjust my method names accordingly. The updated code reflects what I *should* have put initially. – CaptainProg Nov 04 '12 at 14:19
  • Ah....it was *edit the answer*, not *the question*....and I was talking with Abizem....sorry for the confusion :) – Rad'Val Nov 04 '12 at 14:22
  • 1
    @CaptainProg I think you're barking up the wrong tree. Fix the obvious problem - your delegate method is wrong. Within your delegate you are trying to do something to an object, but you are sending the message to a class. – Abizern Nov 04 '12 at 14:24
  • @Abizern Could you elaborate on this please? Is the problem in my '@protocol CustomUIViewDelegate '? I understand that a class method acts on a class (as opposed to an instance method), so do I need to use an instance method instead? – CaptainProg Nov 04 '12 at 14:31