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 elegant way to transfer data from a view to its controller?
All help is greatly appreciated and I always accept an answer!
You’re looking for
Delegationor aData Source. You can see more information about this here, Delegation and Data SourcesA brief example of this would be, something along the lines of this:
Of course,
@synthesizeyourdelegateinMyViewSubclass.mNow in the class’s header, that you want the delegate of
MyViewSubclassto be, you need to conform to the `MyViewSubclassDelegate Protocol.In your
@implementationofMyViewController., implement theMyViewSubclassDelegatemethod of-(void)didTouchView.When you initialize and create your
MyViewSubclassobject, you setMyViewControlleras the delegate: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 !