开发者

Why does dot notation work and not brackets?

So I'm calling this:

[leftSwi开发者_运维问答tch hidden:NO];

but the iPhone Simulator just crashes (no compiler errors) when I click on the Segmented Control that calls the IBAction that this code is from.

However, as soon as I change this to:

leftSwitch.hidden = NO;

it works...I made no other changes.


You want

[leftSwitch setHidden:NO];

Note the automatic change in name-- the method version gets the set prefix.


The default methods synthesized for properties are

[foo bar]

which is the getter, and

[foo setBar:other]

which is the setter.

But the property shorthand allows you to access these methods by using dot notation so it appears that you are accessing like any other ivar, but you are really using these synthesized properties in the background. in the property declaration, you can change the default names, but it is best to leave it based on the normal Objective C conventions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜