small medium large xlarge

Generic-user-small
05 Jan 2011, 11:28
Ric Levy (21 posts)

I am trying out the suggestion at the end of Chapter 8 to set up a button that removes items from the shopping list.

So far, I have got this in the header:

- (IBAction)removeItemFromShoppingList:(id)sender;

</code>

… and this in the main code file:

- (IBAction)removeItemFromShoppingList:(id)sender
{
         [my code]
}

</code>

I have saved everything, and tried restarting everything, but when I go to Interface Builder and right-click my “remove” button there is no “removeItemFromShoppingList” under sent actions. What am I doing wrong? Thanks.

Generic-user-small
05 Jan 2011, 14:58
Tim Isted (105 posts)

Just to check, if you’re right-clicking on the Remove button, are you then dragging out from the Selector to File’s Owner, to get the popup list of possible actions? I find it easier to connect the other way around—right click on the File’s Owner object and drag from the action over to the control I want to use to trigger the action.

Otherwise, everything should be fine, so perhaps you’re running into this: http://forums.pragprog.com/forums/132/topics/8381

Generic-user-small
05 Jan 2011, 15:45
Ric Levy (21 posts)

OK, that’s weird. I just reloaded XCode and there it was in the File’s Owner object! I thought I’d looked there before but maybe I just looked at the Remove button. (Although - shouldn’t it be in both?). Or maybe it’s just reappeared after quitting everything and restarting again…

Anyway, this is the code I came up with. Seems to work OK but I’m interested to know if I did it “right” :-)

-(IBAction)removeItemFromShoppingList:(id)sender
{
	[shoppingListArray removeObjectAtIndex:[shoppingListTableView selectedRow]];
	[shoppingListTableView reloadData];
}

</code>

Thanks!

Generic-user-small
05 Jan 2011, 16:58
Tim Isted (105 posts)

Yes, that’s exactly the right code! You’ll revisit this in Chapter 9, to demonstrate an “Are you sure you want to do that?” alert before deletion.

The action method name itself won’t appear in the black HUD popup window for the button until you’ve linked it up. Before a connection is made, any control that supports target-action (like the button) will just show an empty “selector” connection. This is what can be set to any @IBAction@ method on any other object; once it’s set, the connection in the control’s HUD will show the target object and method name.

You must be logged in to comment