关于实例变量及其属性声明的问题
如果我在标头中的括号之间声明实例变量和对象,并且前面带有“IBOutlet”,我是否必须设置对象属性?
这是否也意味着它们是私有的?对他们来说,私有化意味着什么???
If I declare instance variables and objects in my header between brackets with "IBOutlet" in front of them, do I have to set the objects properties?
Also does this mean they are private? What does it mean for them to BE private???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用
@property
和@synthesize
,则不必声明变量。 .h 文件是一个类的 api,因此声明其中的任何内容都倾向于公开而不是私有。要声明 IBOutlet 私有,您需要创建一个类别,
以上代码将位于 .m 文件内。
希望这会有所帮助
If you do
@property
and@synthesize
you do not have to declare variables. The .h file is an api for a class so declaring anything inside it, has an intension to be public rather than private.To declare IBOutlet private, you need to create a category,
Above code will be inside .m file.
Hope this will help
不,不需要为 IBOutlet 设置属性,只需声明它们就足够了
例如:
如果您希望变量是私有的,那么您必须以这种形式声明它:
在类中声明为私有的实例变量只能由该类的实例访问。
No,It is not necessary to set properties for IBOutlets, Just declaring them would be enough
for eg:
If you want the variables to be private then you will have to declare it in this form
Instance variables declared as private in a class can be accessed only by an instance of the class.
您只需将对象的变量声明为 IBOutlet(假设您使用 Interface Builder 连接它们)。它们不一定是属性,除非您有理由将它们设为属性(即您希望其他对象可以访问该变量)。私有属性不能被外部对象访问。
You just have to declare variables of an object as IBOutlets (assuming you are hooking them up using Interface Builder). They don't have to be properties unless you have a reason to make them a property (i.e. you want the variable to be accessible by other objects). A private property can't be accessed by an external object.