What is the proper way to accept user input in a view and then transfer it to that view\'s controller? I know the NotificationCenter is one option, but surely there is a more el
You're looking for Delegation
or a Data Source
. You can see more information about this here, Delegation and Data Sources
A brief example of this would be, something along the lines of this:
//MyViewSubclass.h
@protocol MyViewSubclassDelegate
//Implement your delegate methods here.
-(void)didTouchView;
@end
@interface MyViewSubclass {
iddelegate;
}
@property(nonatomic,assign)iddelegate;
Of course, @synthesize
your delegate
in MyViewSubclass.m
Now in the class's header, that you want the delegate of MyViewSubclass
to be, you need to conform to the `MyViewSubclassDelegate Protocol.
#import "MyViewSubclass.h"
@interface MyViewController : UIViewController
In your @implementation
of MyViewController.
, implement the MyViewSubclassDelegate
method of -(void)didTouchView
.
When you initialize and create your MyViewSubclass
object, you set MyViewController
as the delegate:
myViewSubclass.delegate = self // Self being MyViewController.
In your MyViewSubclass
, when you're ready to forward any information, or simply want to fire a method you would do [self.delegate didTouchView]
Hope this helps !