I am an iOS newbie. I have a navigation bar button which when clicked should execute a function of my own. What is the best way to do that?
UIBarButtonItem *doneBarButtonItem=[[UIBarButtonItem alloc] init];
doneBarButtonItem.title=@"Done";
self.navigationItem.rightBarButtonItem = doneBarButtonItem;
[doneBarButtonItem release];
One way is to init with the target and action:
Another way is to set the target and action after you created it
Target is the instance of the object that will get called. In the case of self, the method will be on this instance of the object.
Action is the method that will get called. Typically, you decorate it with IBAction to hint to the designer that it's an action. It compiles to void.
There's a variety of different init calls you can use, listed in the Instance Methods section here:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html
Also, you can check out a sample in-use here:
How to set target and action for UIBarButtonItem at runtime
Hope this helps!