How to write a delegate protocol using the same method

I want to add some data to 2 different objects, when any button is pressed, I use a delegate, but I do not know how to do it.

@protocol AddContentViewControllerDelegate <NSObject> - (void)AddContentViewControllerDidCancel:(AddContentViewController *)controller; - (void)AddContentViewController:(AddContentViewController *)controller didAddPlayer:(FailedBankInfo *)info; - (void)AddContentViewController:(AddContentViewController *)controller didAddPlayer:(FailedBankDetails *)details; @end 
0
source share
2 answers

Whenever you declare a protocol, you must also create a delegate for the same

 id <AddContentViewControllerDelegate > delegateAddContent 

and create its ans property synthesized in a .m file

 @property (nonatomic) id delegateAddContent 

in .m

 @synthesize delegateAddContent 

Now you will need to send data through the protocol method that you have already defined using your .m file methods.

 [self delegateAddContent]AddContentViewControllerDidCancel:(AddContentViewController *)controller]; 

there may be some class where you want to send the data. This class should match your protocol e.g. β†’

 @interface ClassName : SuperClass<AddContentViewControllerDelegate > 

and then you have to implement protocol methods. / for example β†’ -

  (void)AddContentViewControllerDidCancel:(AddContentViewController *)controller { //the data will be received in the parameters of the method of the protocol implemented.here in controller } 

Also, the class corresponding to the protocol must own the protocol

= yourclassconformingprotocol.delegateController yourself.

You can also define the necessary methods in the @required and optional by @optional protocol

See Apple Documentation Protocol

+3
source

You cannot have two method names that are selected as different only by their parameter types. As for the compiler, the names of your second and third methods in the protocol are AddContentViewController:didAddPlayer:

+2
source

Source: https://habr.com/ru/post/915634/


All Articles