Is it better to alloc/dealloc new UIBarButtonItems when toggling Edit/Done? Why?

Posted by cambria on Stack Overflow See other posts from Stack Overflow or by cambria
Published on 2010-03-16T05:40:50Z Indexed on 2010/03/16 5:46 UTC
Read the original article Hit count: 176

Apple's documentation implies that for a UITableView editable with an "Edit/Done" button, you should create and destroy the button each time it's toggled.

Here's a snippet of code "BonjourWeb" sample code project that does this:

if (editing) {
    // Add the "done" button to the navigation bar
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
                                   initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction:)];

    self.navigationItem.leftBarButtonItem = doneButton;
    [doneButton release];

    [self addAddButton:YES];
} else {
    if ([self.customs count]) {
        // Add the "edit" button to the navigation bar
        UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editAction:)];

        self.navigationItem.leftBarButtonItem = editButton;
        [editButton release];
    }

Is this really better than just editing the title of the button? Is there some performance optimisation that I'm not seeing? Or is this just bad example source?

© Stack Overflow or respective owner

Related posts about uikit

Related posts about iphone