UA-17470720-3

Jump to content


Photo
- - - - -

Hide/Show a section after Done/Edit tapped

models sections cells view-controllers

  • Please log in to reply
4 replies to this topic

#1 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 25 September 2014 - 02:01 AM

Hi, 

 

on a typical iPad only landscape app, based on the Core Data sample, I add in the viewDidLoad of RootViewController a new section:

 

SCTableViewSection *s = [SCTableViewSection section];  
[s addCell:c];
[detailModel addSection:s];
 

 

Now, I'd like that this section and its contained cell, shows/hides after tapping the edit/done button.
 
I use for example this:
self.actions.editButtonTapped = ^BOOL(SCTableViewController *viewController) {
return TRUE;
};
 
 
in the viewDidLoad method of DetailViewController, as it was not firing in the RootViewController.
 
How can I make it possible to hide/show the section I created, within the edit button tapped method?
 
I browsed the forum and documentation, but no success. For example, in the edit button tapped I tried
[viewController.tableViewModel removeSectionAtIndex:2]
 
but in the log I have
Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
 

Anyone could help me?

 

Thank you very much!

Fabio

 
 

 

 



#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 25 September 2014 - 03:05 AM

Hi fabiensen,

 

As well as removing the section from the model you have to delete it from the table as well:

 

[viewController.tableViewModel.tableView deleteSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationAutomatic];

 

HTH


Cheers,

Dave

www.dgapps.ie

#3 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 25 September 2014 - 06:25 AM

Hi HTH,

 

thank you for your reply, much appreciated!

 

However, with your code, let's say placed on the edit button tapped event, I get (whatever index I try in place of 2):

 

 

Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (3) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).'

 

It is like the app knows there are 3 sections, but then crashes, because I am removing one section. Although I can understand the log message, what I try to achieve is just to hide the added section (with index 2) and show it again after one taps Done. 

 

The best scenario would be to do something like this:

 

[customSectionWithACertainIndex setHidden:yes];

 

but I can hardly figure how I can get a reference of that section from another class (it is created in the RootController, but the tap is intercepted in the Detail Controller) and, mostly, sets it hidden...

 

Any idea?

 

Thanks!



#4 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 25 September 2014 - 06:41 AM

Hi,

 

for those with the same need, I managed to solve it in this way. This assumes however, that the section (or cell) you are trying to hide is the last one, but, knowing the index of it could do the job...

 

 

 self.actions.editButtonTapped = ^BOOL(SCTableViewController *viewController) {

 

        [[[viewController.tableViewModel.tableView visibleCells] lastObject] setHidden:YES];

 

        return TRUE;

 };


  • Tarek likes this

#5 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 25 September 2014 - 07:03 AM

Hi fabiensen,

 

setHidden is maybe not the best way of achieving things, but if it works it works.

 

 

Just to be certain, you need to do both, remove from the model and delete from the table:

 

[viewController.tableViewModel removeSectionAtIndex:2]
[viewController.tableViewModel.tableView deleteSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationAutomatic];


  • Tarek likes this
Cheers,

Dave

www.dgapps.ie





Also tagged with one or more of these keywords: models, sections, cells, view-controllers

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users