Are you looking for Delegation or Data Source . You can see more information about this here, Delegation and data sources
A brief example of this would be something like this:
//MyViewSubclass.h @protocol MyViewSubclassDelegate //Implement your delegate methods here. -(void)didTouchView; @end @interface MyViewSubclass { id<MyViewSubclassDelegate>delegate; } @property(nonatomic,assign)id<MyViewSubclassDelegate>delegate;
Of course @synthesize your delegate in MyViewSubclass.m
Now in the title of the class to which you want to delegate MyViewSubclass , you need to comply with the MyViewSubclassDelegate protocol.
#import "MyViewSubclass.h" @interface MyViewController : UIViewController <MyViewSubclassDelegate>
In @implementation MyViewController. use the MyViewSubclassDelegate method -(void)didTouchView .
When you initialize and create your MyViewSubclass object, you set MyViewController as a delegate:
myViewSubclass.delegate = self
In your MyViewSubclass , when you are ready to redirect any information or just want to run a method that you would do [self.delegate didTouchView]
Hope this helps!
skram source share