From a784d0a4a6a8457296ba2c6128e9da29cdd1fcfd Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Tue, 1 Feb 2011 11:00:09 -0800 Subject: Refactor edit button in SectionsController; use system provided UIBarButtonItems. --- MobileCydia.mm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'MobileCydia.mm') diff --git a/MobileCydia.mm b/MobileCydia.mm index 023284a..392c173 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6670,15 +6670,26 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } +- (void) updateNavigationItem { + [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")]; + if ([sections_ count] == 0) { + [[self navigationItem] setRightBarButtonItem:nil]; + } else { + [[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] + initWithBarButtonSystemItem:(editing_ ? UIBarButtonSystemItemDone : UIBarButtonSystemItemEdit) + target:self + action:@selector(editButtonClicked) + ] animated:([[self navigationItem] rightBarButtonItem] != nil)]; + } +} + - (void) setEditing:(BOOL)editing { if ((editing_ = editing)) [list_ reloadData]; else [delegate_ updateData]; - [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")]; - [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")]; - [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain]; + [self updateNavigationItem]; } - (void) viewDidAppear:(BOOL)animated { @@ -6802,13 +6813,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [filtered_ addObject:section]; } - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:([sections_ count] == 0 ? nil : UCLocalize("EDIT")) - style:UIBarButtonItemStylePlain - target:self - action:@selector(editButtonClicked) - ] autorelease] animated:([[self navigationItem] rightBarButtonItem] != nil)]; - + [self updateNavigationItem]; [list_ reloadData]; _trace(); } -- cgit v1.2.3