HOW TO CREATE VIEW DELEGATE IN IOS

Jayne Spooner

Total Post:21

Points:147
Posted by  Jayne Spooner
 570  View(s)
Ratings:
Rate this:

I have create a delegate in our custom UIView, here is the code:

@protocol CustomViewDelegate
@optional
- (void) CustomViewDidInitialize:(CustomView *)customView;
@end

 

@interface CustomView : UIView {   
@private
}

@property(nonatomic, assign) id<CustomViewDelegate> delegate;

@end

The above code is not working because the CustomView interface has not been declared at the time of the CustomViewDelegate declaration.
So, now I tried it by adding a prototype ala C++ before the @protocol like this:

@interface FunView;

But it's also not solving my problem, so anyone have the solution then please tell me, thank you.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to create view delegate in iOS

    To forward declared protocols do like this:

    @protocol CustomViewDelegate;

    @interface CustomView : UIView {   
    @private
        id<CustomViewDelegate> delegate;
    }

    @property(nonatomic, assign) id<CustomViewDelegate> delegate;
    @end

    @protocol CustomViewDelegate
    @optional
    - (void) customViewDidInitialize:(CustomView *)customView;
    @end

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!