2011-08-12 33 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'部分沒有實現聲明的方法。 –

相關問題