Friday, May 31, 2013

UIBarButtonItem UIBarButtonSystemItemBookmarks example in Objective C (iOS).


UIBarButtonItem UIBarButtonSystemItemBookmarks


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 UIBarButtonSystemItemBookmarks example.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
     UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];

     NSArray *myToolbarItems = [[NSArray alloc] initWithObjects: item, nil];
     [self setToolbarItems: myToolbarItems];
     [myToolbarItems release];

    }
    return self;
}

Example of [UIBarButtonItem UIBarButtonSystemItemBookmarks].
- (void)viewDidLoad
{
    [super viewDidLoad];

    .... code where you set up the table view...

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(toggleEditing)];    
    self.navigationItem.rightBarButtonItem = addButton;
    [addButton release];

UIBarButtonItem UIBarButtonSystemItemBookmarks example.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    if (editing)
    {
        // We are changing to edit mode
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleEditing)];    
        self.navigationItem.rightBarButtonItem = doneButton;
        [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
        [doneButton release];
        self.navigationItem.title = @"Add to Favourites";
    }
    else
    {
        // We are changing out of edit mode
        self.navigationItem.title = [selectedCellItem valueForKey:@"name"];
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(toggleEditing)]; 
        self.navigationItem.rightBarButtonItem = addButton;
        [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
        [addButton release];
        self.navigationItem.title = [selectedCellItem valueForKey:@"name"];
    }
}

End of UIBarButtonItem UIBarButtonSystemItemBookmarks example article.