views:

749

answers:

1

Hello,

I have several UIBarButtonItems, and I want to set the action when you press it programmaticly. How can I do this? Please give in-depth instructions since i just started to work with the SDK.

EDIT: if it would be possible non-programmaticly, please also reply :)

The action is going to Google.com, and the button is the search button in this project: (download): click here

A: 

First create an outlet to the items in IB. Then you can modify the methods called by using [myItem setTarget:] and [myItem setAction:].

See target action

ETA: Is there any particular reason you want to do it programmatically?

ETAA: To do it non-programmatically, make a function with return type IBAction, and argument (id)sender, like so:

- (IBAction)myMethod:(id)sender;

With whatever implementation you like. Then, in IB, drag an object object from the Library to the MainWindow.xib window, and in the identity window (cmd-6), give it the class that has your function. Then, in the connections window of that object (cmd-5), you can drag from your function name to whichever interface object you want.

I strongly suggest you read mac dev on IB. The connections and bindings section will discuss this particular issue. Also, a tutorial like so: yet another tutorial will probably help.

yodie
how can i do the same non-programmatically then?
TutorialPoint
cause that would be better :)
TutorialPoint
but how am i going to go with the action then like you see in the appdelegate.m file in the project download?
TutorialPoint
see edit.......
yodie
can you give me more in-depth instructions (so really where to put everything and how to do everything) or can you modify my project? Thanks :)
TutorialPoint
I think the best thing for you is to do a tutorial or two. Most basic iPhone apps follow the same pattern, so if you know how to do a real 'Hello World', you'll know how to do your project. If I just rewrite your code, you won't know the basic design patterns (MVC, for example) that iPhone / Cocoa apps tend to use.
yodie
what do you exactly mean by 'class that has your function'? Do you mean the .m document?
YourComputerHelpZ
if you mean the .m document, why doesn't it show the function???
YourComputerHelpZ
OK, i did i think so what you wanted me to do... But it still doesn't work :( Can you look at it? Thanks! http://gdscei.com/zEzo%202.zip
YourComputerHelpZ