0

当按下某个按钮时,我想将一些数据添加到 2 个不同的实体中,我正在使用委托,但我不知道该怎么做。

@protocol AddContentViewControllerDelegate <NSObject>

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

2 回答 2

3

每当您声明一个协议时,您还必须为其创建一个委托

id <AddContentViewControllerDelegate > delegateAddContent

并在 .m 文件中创建其属性 ans synthesize

@property (nonatomic) id delegateAddContent

@synthesize delegateAddContent

现在您必须通过您已经通过 .m 文件方法定义的协议方法发送数据。

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

可能有一些你想发送数据的类。那个类必须符合你的协议,例如-->

@interface ClassName : SuperClass<AddContentViewControllerDelegate >

然后你必须实现协议的方法。/例如-->-

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

符合协议的类也必须取得协议所有权

yourclassconformingprotocol.delegateController=self.

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

See Apple's documentation on protocol

于 2012-05-12T13:04:39.857 回答
2

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:.

于 2012-05-12T13:11:49.150 回答