【发布时间】:2011-11-03 09:07:21
【问题描述】:
我有两个协议
@protocol P1
-(void) printP1;
-(void) printCommon;
@end
@protocol P2
-(void) printP2;
-(void) printCommon;
@end
现在,我在一个类中实现这两个协议
@interface TestProtocolImplementation : NSObject <P1,P2>
{
}
@end
如何为“printCommon”编写方法实现。当我尝试执行时,出现编译时错误。
是否有可能为“printCommon”编写方法实现。
【问题讨论】:
-
你能发布你的错误和你的实现吗?
-
#pragma mark - #pragma mark P1 协议方法 -(void)printP1 { NSLog(@"print p1"); } -(void) printCommon { NSLog(@"Print P1"); } #pragma mark - #pragma mark P2 协议方法 -(void)printP2 { NSLog(@"print p2"); } -(void) printCommon { NSLog(@"Print P2");错误:重新定义'-[TestObjectLifeCycle printCommon]' 当我删除任何一个“printCommon”方法实现时,它运行良好。
标签: objective-c oop ios5 protocols