简体   繁体   English

为什么UIButton可以向私有方法发送消息?

[英]Why a UIButton could send message to a private method?

In the first case in the book iOS programming: The Big Nerd Ranch Guide, they only implemented a method - (IBAction)showQuestion:(id)sender between the @implementation @end , but did not declare it in the @interface @end in the .h file. 在iOS编程的第一个案例中:The Big Nerd Ranch Guide,他们只在@implementation @end之间实现了一个方法- (IBAction)showQuestion:(id)sender ,但没有在@interface @end中声明它.h文件。 As far as I know, if you don't declare methods in the @interface @end , the method cannot be accessed from outside. 据我所知,如果你没有在@interface @end声明方法,则无法从外部访问该方法。 But the truth is the UIButton did send message to the controller instance, that confused me. 但事实是,UIButton确实向控制器实例发送了消息,这使我感到困惑。 Do I have a wrong idea about private method? 我对私有方法有错误的想法吗?

InterfaceBuilder looks in all source files, headers and implementation, to find IBOutlets and IBActions. InterfaceBuilder查找所有源文件,标头和实现,以查找IBOutlets和IBActions。 Private or not, it sees all declared methods, so you can connect them to interface components. 私有与否,它会看到所有声明的方法,因此您可以将它们连接到接口组件。 During runtime, all methods are equal, so of course the button can call a private method. 在运行时,所有方法都相同,因此按钮可以调用私有方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM