Welcome, Guest
Username Password: Remember me

Problems with removeCellAtIndex
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Problems with removeCellAtIndex

Problems with removeCellAtIndex 1 year, 5 months ago #1

Hi,

I'm currently using the below code to selectively remove a cell on a section after the user has selected a cell through the SCPropertyTypeSelection. I'm placing the code in detailViewDidDisappearForRowAtIndexPath :

- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewDidDisappearForRowAtIndexPath:(NSIndexPath *)indexPath{

if (tableViewModel.tag == 0) {

if ([tableViewModel activeCell].tag == InspectionTypeCell ) {
SCArrayOfObjectsSection *section = (SCArrayOfObjectsSection *)[tableViewModel sectionAtIndex:0];
[section removeCellAtIndex:InspectionHWSCell];
}
}

I'm finding that the cell never gets removed from the view although the removeCellAtIndex:InspectionHWSCell is being called in the SCTableViewSection code. Any ideas on what might be going on ?? Do I need to reload/refresh the view somehow ? Thanks.
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Problems with removeCellAtIndex 1 year, 5 months ago #2

Hi Phil,

After removing the cell from the section, you'll also have to remove it from your UITableView by calling [self.tableView reloadData]. STV doesn't do this removal automatically for three main reasons:

1- The UITableView may not have been rendered yet when you do this removal operation.
2- For optimization purposes: You might be doing several operations on the section and don't want them committed in realtime to your actual UI.
3- For customization purposes: You may want to remove it using certain animations or with no animation at all.

Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Problems with removeCellAtIndex 1 year, 5 months ago #3

ok Thanks for that. [self.tableView reloadData] didn't seem to work so I tried [tableViewModel modeledTableView] reloadData] and that worked great.

Now if I want to be able to re-add that same cell (since the user has selected something specific), is that possible ?? I realise that there is a addCell available but I dont have any reference to that cell. Or will I need to be hold a reference to that cell when I remove it. Or is there something in the SCTableViewSection to refresh itself somehow ?
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Problems with removeCellAtIndex 1 year, 5 months ago #4

Hi Phil,

It's a perfectly fine solution if you just retain the removed cell and add it later to the section (you'll also then need to call [tableModel.modeledTableView reloadData]).
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Problems with removeCellAtIndex 1 year, 5 months ago #5

Thanks I'll try that.

Also my app is running on an iPad and so I'm using the customDetailTableViewModelForRowAtIndexPath method to generate the detailModel (like in the sample code). However when I use the removeCellAtIndex and then a reloadData its still not removing the cell.

 
- (SCTableViewModel *)tableViewModel:(SCTableViewModel *)tableViewModel
customDetailTableViewModelForRowAtIndexPath:(NSIndexPath *)indexPath
{
SCTableViewModel *detailModel = nil;
 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
detailModel = [SCTableViewModel tableViewModelWithTableView:self.detailViewController.tableView
withViewController:self.detailViewController];
 
SCArrayOfObjectsSection *section = (SCArrayOfObjectsSection *)[tableViewModel sectionAtIndex:indexPath.section];
NSManagedObject *managedObject = [section.items objectAtIndex:indexPath.row];
 
if ([managedObject isKindOfClass:[Inspection class]]) {
// Do Stuff
}
 
SCArrayOfObjectsSection *detailSection = (SCArrayOfObjectsSection *)[detailModel sectionAtIndex:indexPath.section];
[detailSection removeCellAtIndex:7];
[[detailModel modeledTableView] reloadData];
[self.tableView reloadData];
}
return detailModel;
}
 
 


Am I performing the reloadData on the correct tableModel ? Or does that code look wrong elsewhere ?
(Note I'm not using the Beta yet)
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Problems with removeCellAtIndex 1 year, 5 months ago #6

Hi again Phil,

I think I made a mistake due to not carefully examining the code you posted in your very first post. What I missed is that you're using an SCArrayOfObjectsSection, and not just a normal SCTableViewSection. The proper way of removing a cell from an SCArrayOfObjectsSection is to remove its corresponding object from the "items" array (inherited from the SCArrayOfItems superclass). You should then call [tableModel.modeledTableView reloadData] for the same reasons discussed earlier. "removeCellAtIndex" should never be called for an SCArrayOfObjectsSection. I really apologize for the misunderstanding.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.82 seconds