开发者

IBActions foo and foo:

In Interface Builder I in Library开发者_运维知识库->Classes when I select a class that I made in XCode, then display the Actions, I can see two with the same name:

foo
foo:

What is the difference between these two foos?


foo is a method that doesn't accept any arguments. foo: passes an argument or arguments into its method.

Example:

-(IBAction)foo;

will be shown as foo in IB.

-(IBAction)foo:(id)sender;

will be shown as foo: in IB.

I don't know why they have the same name, do you have them set that way?


IB assumes if your creating the class files using IB that you will using the sender and so it creates the construct

-(IBAction)foo:(id)sender;

You usually will need info about the sender so I would stick with that construct. If you don't need the sender in your implementation, simply ignore it.

-(IBAction)foo:(id)sender {
    [someObject doAMethod];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜