Welcome, Guest
Username Password: Remember me

preserve tableModel.activeCell
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: preserve tableModel.activeCell

preserve tableModel.activeCell 1 year, 8 months ago #1

currently i get a crash when your framework tries to access activeCell.

i regenerate my whole model (it's not large) on every viewWillAppear

activeCell turns into garbage and on the next cell touch it crashes here:

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SCTableViewCell *cell = [self cellAtIndexPath:indexPath];
if(cell != self.activeCell)
{
if(self.activeCell.autoResignFirstResponder) <--- CRASH!!!
 


my workaround is to add

 
[tableModel clear];
tableModel.activeCell = nil; // clear activecell, fix crash
 



But that's not optimal because it's error phrone AND Sensible TableView should remember the last selected IndexPath and restore it (so that the last cell fades out)

Thanks!
  • steipete
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Karma: 0

Re: preserve tableModel.activeCell 1 year, 8 months ago #2

Would you please provide more code regarding how you regenerate your model in in viewWillAppear so that we could replicate the issue? For your convenience, also feel free to send us your project at our support email.

Thank you very much.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Last Edit: 1 year, 8 months ago by tarekskr.

Re: preserve tableModel.activeCell 1 year, 8 months ago #3

sure, here u go

 
- (void)createSettings {
[tableModel clear];
tableModel.activeCell = nil; // preserve a crash on reselection, downside: kills dynamic flashing
SCTableViewSection *generalSection = [SCTableViewSection sectionWithHeaderTitle:NSLocalizedString(@"", @"")];
SCTableViewCell *locationCell = [SCTableViewCell cellWithText:NSLocalizedString(@"Locations", @"")];
SCTableViewCell *unitsCell = [SCTableViewCell cellWithText:NSLocalizedString(@"Units", @"")];
SCTableViewCell *priceCell = [SCTableViewCell cellWithText:NSLocalizedString(@"Price", @"")];
priceCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[generalSection addCell:locationCell];
[generalSection addCell:unitsCell];
[generalSection addCell:priceCell];
 
(...) you get the idea
 
[tableModel addSection:generalSection];
 
[self.tableView reloadData];
}
 
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self createSettings];
}
 
 


tableModel is a class variable
  • steipete
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Karma: 0

Re: preserve tableModel.activeCell 1 year, 8 months ago #4

The bug we have is that the clear method of SCTableViewModel should assign the activeCell property to nil. We will send you an updated version with the issue resolved, thank you very much!

Now regarding your dynamic flashing comment, may I ask why are you regenerating the whole table view model on every viewWillAppear?
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: preserve tableModel.activeCell 1 year, 8 months ago #5

well, it's kinda convenience, as there are just 7 or 8 cells, and the content can change in subviews
it's easier than to remember all the cells and change their properties.

(so i can have just one "model generator" and just re-run that.)
  • steipete
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Karma: 0

Re: preserve tableModel.activeCell 1 year, 8 months ago #6

Hi again Peter,

I strongly recommend doing the following as it is the best practice, in addition to being much more optimized:

 
- (void)viewDidLoad
{
...
 
SCTableViewSection *section = [SCTableViewSection sectionWithHeaderTitle:nil];
[tableModel addSection:section];
[section addCell:[SCTableViewCell cellWithText:@"Cell 1"]];
[section addCell:[SCTableViewCell cellWithText:@"Cell 2"]];
[section addCell:[SCTableViewCell cellWithText:@"Cell 3"]];
 
...
}
 
- (void)viewWillAppear:(BOOL)animated
{
SCTableViewSection *section = [tableModel sectionAtIndex:0];
[section cellAtIndex:0].textLabel.text = @"new Cell 1 value";
[section cellAtIndex:1].textLabel.text = @"new Cell 2 value";
[section cellAtIndex:2].textLabel.text = @"new Cell 3 value";
}
 
 


This will also preserve any selection you have.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
  • Page:
  • 1
Time to create page: 1.03 seconds