在谷歌上搜索了这一困惑之后,我发现放置找出的最佳地点是:
@interface GallantViewController : UIViewController
@property (nonatomic, weak) IBOutlet UISwitch *switch;
@end
但是根据我所说的,现在switch
变量在GallantViewController
之外是可见的。这不奇怪吗?我认为这种方法是错误的:
@interface GoofusViewController : UIViewController {
IBOutlet UISwitch *_switch
}
@end
就像这样,动起来就能解决问题。为什么要操作一个按钮,例如来自另一个类的按钮,而不是在GallantViewController
中实现它的逻辑
发布于 2015-03-02 10:19:43
@interface
可以同时出现在.h
文件(公共属性)和.m
文件(私有属性)中。IBOutlets
应该在.m
文件中声明。
例如,下面是一个视图控制器的示例.m
文件
#import "MainViewController.h"
@interface MainViewController ()
// the following property is not visible outside this file
@property (weak, nonatomic) IBOutlet UIView *someView;
@end
@implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
@end
从技术上讲,@interface
文件中的.m
是类扩展名(也称为类上的匿名类别),但这并没有实际意义。它只是将私有属性添加到类中的一种方法。
https://stackoverflow.com/questions/28806489
复制相似问题