我想隐藏一些我在其他对象中使用时亲自制作的方法。
如何隐藏这些方法?如果我没有在'.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 :(得分: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
答案 1 :(得分:0)
使用@private后跟@end在实现文件中声明它们通过定义,目标c没有私有方法
Best way to define private methods for a class in Objective-C