In Objective-C problem in creating view delegate

Total Post:214


 1355  View(s)
Rate this:

I have a problem with my delegate, when I was trying to create a delegate protocol in a custom UIView.

Here is my code:

@protocol MyViewDelegate


- (void) myViewDidInitialize:(MyView *)myView;



@interface MyView : UIView {   



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


This doesn't work because the MyView interface has not been declared at the time of the MyViewDelegate declaration. I was tried to adding a prototype before the @protocol:

@interface MyView;

But this just drives the compiler nuts. How am I supposed to do this?

  1. Re: In Objective-C problem in creating view delegate

    Here is your problems solution, I think you can forward the declared protocol:

    @protocol MyViewDelegate;
    @interface MyView: UIView{
    @private id<MyViewDelegate> delegate;
    @property(nonatomic, assign) id<MyViewDelegate> delegate;
    @protocol MyViewDelegate
    @optional -(void) myViewDidInitialize:(MyView *)myView;

      Modified On Apr-10-2018 04:27:06 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.