문제

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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top