Home > DeveloperSection > Forums > In Objective-C problem in creating view delegate
Tarun Kumar

Total Post:210

Points:1614
Posted on    September-25-2015 12:21 AM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 505  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

@optional

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

@end

 

@interface MyView : UIView {   

@private

}

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

@end

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?



Jessica James
Jessica James

Total Post:16

Points:114
Posted on    September-25-2015 11:44 PM

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;
@end

@protocol MyViewDelegate
@optional -(void) myViewDidInitialize:(MyView *)myView;
@end


Modified On Mar-18-2016 11:23:11 PM

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

Follow MindStick