oratis
oratis

Reputation: 828

How to write a delegate protocol withe two same method

I want to add some data into 2 different entities when certain button is pressed, I am using delegate,but I don't know how to do that.

@protocol AddContentViewControllerDelegate <NSObject>

- (void)AddContentViewControllerDidCancel:(AddContentViewController *)controller;
- (void)AddContentViewController:(AddContentViewController *)controller didAddPlayer:(FailedBankInfo *)info;
- (void)AddContentViewController:(AddContentViewController *)controller didAddPlayer:(FailedBankDetails *)details;
@end

Upvotes: 0

Views: 1048

Answers (2)

Phillip Mills
Phillip Mills

Reputation: 31016

You can't have two method names that are selected as different only by their parameter types. As far as the compiler is concerned, the names of your second and third methods in the protocol are both AddContentViewController:didAddPlayer:.

Upvotes: 2

Abhishek Singh
Abhishek Singh

Reputation: 6166

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

id <AddContentViewControllerDelegate > delegateAddContent

and create its property ans synthesize in the .m file

@property (nonatomic) id delegateAddContent

in .m

@synthesize delegateAddContent

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

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

there might be some class where you want to send the data.That class must conform to your protocol e.g-->

@interface ClassName : SuperClass<AddContentViewControllerDelegate >

and then you will have to implement the methods of the protocol./ eg -->-

 (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 that conforms to protocol must take the protocol ownership

yourclassconformingprotocol.delegateController=self.

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

See Apple's documentation on protocol

Upvotes: 3

Related Questions