0

I'm new to iOS development and a bit stucked with such problem.

In my iphone app I'm using this awesome dropdown view controller https://github.com/nmattisson/DropdownMenu via Cocoapods.

I'm extending DropdownMenuController in my own MyDropdownMenuController:

MyDropdownMenuController.h

#import "DropdownMenuController.h"

@interface MyDropdownMenuController : DropdownMenuController

@end

I would like to override this drawOpenLayer (https://github.com/nmattisson/DropdownMenu/blob/master/DropdownMenu/DropdownMenuController.m#L126) method inside my controller instance, but unfortunately compiler says it's not possible:

MyDropdownMenuController.m

- (void)drawOpenLayer {
   // compiler says 
   // "No visible @interface for "DropdownMenuController" declares the selector "drawOpenLayer"
   [super drawOpenLayer];
}

Is it possible to override this method without actually updating external interface etc.?

Kosmetika
  • 20,774
  • 37
  • 108
  • 172
  • 1
    Can't you modify the DropdownMenuController.h file to declare that method? – rdelmar Apr 29 '14 at 18:30
  • You could implement `drawOpenLayer` without calling `[super drawOpenLayer]` but of course you lose whatever that functionality is and you would need to implement it all yourself. – rmaddy Apr 29 '14 at 18:31
  • @rdelmar I do not want to modify DropdownMenuController.h because it's a cocoapod package – Kosmetika Apr 29 '14 at 18:33

1 Answers1

1

You can create a category that defines the method

@interface DropdownMenuController (MichaelHacksIt)

- (void)drawOpenLayer;

@end

(no need to define the @implementation for this, because it's already implemented.)

Then you may just call that method.

Disclaimer: Btw, that's the way to go if you want to call undocumented methods and don't care about Apples approval. In this case, there is nothing wrong with it, because you're not hacking Apple code, and Apple doesn't care if you hack some CocoaPods program. However, you are depending on internals of a third-party package, so there may be problems when you update that package next time...

bbum
  • 162,346
  • 23
  • 271
  • 359
Michael
  • 6,451
  • 5
  • 31
  • 53
  • @bbum: thanks for editing. now it makes much more sense – Michael Apr 29 '14 at 20:42
  • @rdelmar (Responding to a comment on your deleted answer). Note the subtlety here; the category is just a declaration that the class implements the method and not actually an implementation that replaces the class's original implementation. That is, the intention is to declare that the superclass does, in fact, implement some method such that you can override said method and call it via `[super ...];`. It is passably sleazy when applied to an open source framework and verboten when used against system provided classes. – bbum Apr 30 '14 at 05:55