2011-08-12 37 views
0

我想隐藏一些在其他对象中使用它们的方法。如何隐藏自定义类中的某些方法?

如何隐藏这些方法?如果我没有在'.h'(头文件)中定义,这可能吗?

[.H头文件中的部分内容]

- (void) sequence1; //<= For example, I would like to hide it. 
- (void) sequence2; 
- (void) sequence3; 
- (void) sequence4; 
- (void) sequence5; 
- (void) sequence6; 
- (void) mcpSelect; 
- (void) replay; 
- (void) myTurn; 

- (IBAction)kaPressed:(id)sender; 
- (IBAction)baPressed:(id)sender; 
- (IBAction)boPressed:(id)sender; 

回答

0

如果“隐藏”你只是想以确保他们不会在你的类的公有接口中结束,然后你可以离开他们在.h文件中,所以在导入头文件时没有其他类会看到这些方法。

然后,在你的.m文件,你可以声明额外的方法作为对你的类类别:

@interface uvSecondScreen (PrivateMethods) 
-(void)privateMethod1; 
-(void)privateMethod2; 
@end 

@implementation uvSecondScreen 
// Implementation of all public methods declared in uvSecondScreen.h 

-(void)privateMethod1 { 
    NSLog(@"Entered privateMethod1"); 
} 

-(void)privateMethod2 { 
    NSLog(@"Entered privateMethod2"); 
} 
@end 
+0

如果你离开了名,即'@interface uvSecondScreen()',你会得到一个延伸你是伟大的.. –

+1

。优点是te编译器会抱怨,如果在.m文件中该类的'@ implementation'部分没有实现声明的方法。 –

相关问题