Friday, May 31, 2013

UIBarButtonItem UIBarButtonSystemItemSearch example in Objective C (iOS).


UIBarButtonItem UIBarButtonSystemItemSearch


UIBarButtonSystemItem
Defines system-supplied images for bar button items.

typedef enum {
UIBarButtonSystemItemDone,
UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItemBookmarks,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItemUndo, // iOS 3.0 and later
UIBarButtonSystemItemRedo, // iOS 3.0 and later
UIBarButtonSystemItemPageCurl, // iOS 4.0 and later
} UIBarButtonSystemItem;

UIBarButtonItem UIBarButtonSystemItemSearch example.
//Your actual ViewController
UIBarButtonItem *search = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];   
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightBarButtonItem = search;
[search release];

//Controller that is going to be pushed and will display the new UIBarButtonItem
[self.navigationController pushViewController:newViewController animated:YES];

Example of [UIBarButtonItem UIBarButtonSystemItemSearch].
// 2nd. button - this one does not show up:
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]
                                           initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
                                           target:self
                                           action:@selector(goSearching:)];
// Here I think you wanna add the searchButton and not the filterButton..
self.navigationItem.rightBarButtonItem = searchButton;

UIBarButtonItem UIBarButtonSystemItemSearch example.
// Create button1
UIBarButtonItem *propertiesButton = [[UIBarButtonItem alloc]
                    initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(button1Pressed)];
[buttons addObject:propertiesButton];
[propertiesButton release];

End of UIBarButtonItem UIBarButtonSystemItemSearch example article.