Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Regarding omitting passing itself as a parameter, do you mean like...</p> <pre><code>- (void) pushedStart : (id) sender { //start game } </code></pre> <p>but you can't do </p> <pre><code>[self pushedStart]; </code></pre> <p>because it needs a parameter? If so, what you can do this:</p> <pre><code>id junkID; [self pushedStart: junkID]; </code></pre> <p>JunkID will initialize to whatever the hell it is an unassigned ID assigns to, so you pass it as a reference and just don't use it for anything, which is good if you want to have a "start game" button but have the game automatically start inside of a timer or whatever else you're doing with your buttons</p> <p>As a side note, and getting more into the guts of cocoa, the way it KNOWS (and what YOU must not forget) is that colon. When you call a function you put the variable after a colon [self eat: food]; </p> <p>When you put together the menu item you set it up with target:self, which makes the button use itself (not the layer "self" you use when you call [self eatABanana]) as a target. The button push of </p> <pre><code>menuButton = target:self selector:@selector(pushButton:) </code></pre> <p>is represented like </p> <pre><code>[self pushButton:menuButton] </code></pre> <p>If you forgot that colon, it's the same as calling a function and not passing the variable, which doesn't give a very helpful error message insofar as it doesn't help you locate where the problem is occurring. I've spent hours upon hours chasing down memory crashes resulting from writing @selector(startGame) instead of @selector(startGame:) in those damn menu buttons. I always feel stupid when I finally figure it out.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload