Home > DeveloperSection > Forums > How to create view delegate in iOS
Jayne Spooner
Jayne Spooner

Total Post:21

Points:147
Posted on    December-16-2015 10:59 PM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 286  View(s)
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.



Tarun Kumar

Total Post:213

Points:1635
Posted on    December-17-2015 10:28 PM

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


Don't want to miss updates? Please click the below button!

Follow MindStick