IBOutlet Ad Placement

After searching Google for this confusion, I found out that the best place to post an IBOutlet is:

 @interface GallantViewController : UIViewController @property (nonatomic, weak) IBOutlet UISwitch *switch; @end 

but from what I'm saying, now the switch variable is visible outside of the GallantViewController . Isn't that weird? I thought this wrong method:

 @interface GoofusViewController : UIViewController { IBOutlet UISwitch *_switch } @end 

behaved this way, and his movement would fix it. Why do you want to manipulate a button, for example, from another class, instead of implementing it logically only in the GallantViewController ?

0
source share
1 answer

@interface can be displayed both in the .h file (public properties) and in the .m file (private properties). IBOutlets must be declared in the .m file.

For example, here is an example .m file for a view controller

 #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 

Technically, the @interface in the .m file is an extension of the class (also called an anonymous category in the class), but this has no practical interest. This is just a way to add private properties to a class.

+4
source

All Articles