ios - 在 iOS 中声明条件委托(delegate)方法

标签 ios objective-c delegates protocols

我正在寻找一种方法来声明委托(delegate)方法的实现有条件地相互链接。我知道 @required@optional 标记特定方法的方式。但是我希望有一种方法可以根据需要标记一个方法,如果另一个方法被实现的话。这可能吗?

我喜欢做的事情是这样的:

考虑以下委托(delegate)方法:

- (void) firstSuccessDelegateMethod;
- (void) firstErrorDelegateMethod;
- (void) secondSuccessDelegateMethod;
- (void) secondErrorDelegateMethod;

有没有办法声明类似的东西

如果实现了firstSuccessDelegateMethod,则需要firstErrorDelegateMethod 如果实现了secondSuccessDelegateMethod,则需要secondErrorDelegateMethod

谢谢!

最佳答案

遗憾的是,这是不可能的,尽管您总是可以将两个委托(delegate)方法合并为一个,例如,

- (void)delegateMethodWithResult:(id)result error:(NSError *)error 

关于ios - 在 iOS 中声明条件委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30704933/

相关文章:

iphone - 为方法传递 block

c# - 如何正确等待异步委托(delegate)?

iphone - 增加 tabBarItem 图像大小

谓词表达式中的 iOS Core Data 二元运算

ios - 如何手动将下一个信号发送到 RxSwift 中的可观察对象?

ios - AFNetworking 从错误端点获取响应 JSON

ios - 快速向后滑动时,UITableViewCell 不会被取消选择

objective-c - 从主应用程序启动 Mac OS X (LoginItem) 助手应用程序

c# - 注册来自不同类的回调

cocoa - (Cocoa) 我可以同时进行子类化和委托(delegate)吗?