Using @protocol

Discussion in 'iOS Programming' started by beardedpig, Jan 19, 2009.

  1. macrumors member

    Dec 17, 2008
    I have written a class that is a subclass of UIImageView and has some custom methods in it.

    I now find I need yet another UIImageView subclass along the same lines but with a different version of some of the methods.

    I have been looking at using @Protocol but suspect as usual I haven't grasped the bleedin concept!

    My thoughts were this:

    Create the inteface file of the custom class like with the protocol in it like so:

    #import <UIKit/UIKit.h>
    @interface CustomImageView : UIImageView {
    @protocol CustomImageViewMethods
    -(void) doubleTap;
    I read that I do not need to create an implementation file as the class subclassing this will do so.

    So I then create a class of type CustomImageView like so

    @interface myImageView : CustomClassView <CustomImageViewMethods> {
    and subsequently get more errors than you can wave a stick at!

    Am I so far off beam I should be thrashed with a large iceberg lettuce?
  2. macrumors newbie

    Jan 14, 2007
    Just out of curiosity, what are the errors, specifically?
    Also, does your myImageView class have a call to doubleTap the exact type and argument set that the protocol states?
  3. macrumors 68030


    Sep 2, 2008
    Couple random comments.

    @protocol is related to delegation. If you're not setting up a delegate then your protocol doesn't make sense.

    @protocol goes outside the @interface, not inside as you've shown it. The protocol is like a class declaration, although it has no code. A given class, the delegate, would adopt the protocol and implement it.
  4. thread starter macrumors member

    Dec 17, 2008
    Hi chaps,

    yes I realise my error not only in protocol usage but also in the fact that all I needed to do was create a custom class of the required type and then subclass this!

    live and and learn :)

Share This Page