Welcome, Guest
Username Password: Remember me

Automatically hide edit button when tableview is empty
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Automatically hide edit button when tableview is empty

Automatically hide edit button when tableview is empty 1 year, 1 month ago #1

Hi!

I was wondering if there was a way to automatically hide the edit button (left navigation bar) when the the table view is empty. Also would it be posssible to disable the "+" button when in edit/deletion mode? Below is what i did to try to achieve this but there are some cases where this approach doesn't work.


 
- (void)viewDidLoad {
[super viewDidLoad];
 
// Instantiate the tabel model
tableModel = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView withViewController:self
withEntityClassDefinition:someClassDef];
tableModel.addButtonItem = self.navigationItem.rightBarButtonItem;
tableModel.autoSortSections = TRUE;
tableModel.hideSectionHeaderTitles = TRUE;
 
if ( tableModel.sectionCount > 0) {
self.navigationItem.leftBarButtonItem = self.editButtonItem;
tableModel.editButtonItem = self.editButtonItem;
}
 
}
 
- (void)tableViewModelWillBeginEditing:(SCTableViewModel *) tableViewModel
{
tableModel.addButtonItem.enabled = NO;
}
 
- (void)tableViewModelDidEndEditing:(SCTableViewModel *) tableViewModel
{
tableModel.addButtonItem.enabled = YES;
 
if (tableModel.sectionCount > 0) {
 
self.navigationItem.leftBarButtonItem = self.editButtonItem;
tableModel.editButtonItem = self.editButtonItem;
}
else
{
self.navigationItem.leftBarButtonItem = nil;
tableModel.editButtonItem = nil;
}
 
}
 
 


Thanks and keep the features coming in .
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7

Re: Automatically hide edit button when tableview is empty 1 year, 1 month ago #2

Hi Harold,

I think we should add these as feature requests to the upcoming STV 2.1 (www.sensiblecocoa.com/forum/announcement...0-released.html#2257)

Regarding your code, the tableViewModelWillBeginEditing and tableViewModelDidEndEditing delegate methods only get called when you assign your model's editButtonItem property to your bar's edit button. Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
Time to create page: 1.38 seconds