Welcome, Guest
Username Password: Remember me

Animated appearance and disappearance of row
(1 viewing) (1) Guest

TOPIC: Animated appearance and disappearance of row

Animated appearance and disappearance of row 1 year, 4 months ago #1

Hi All,

I have a detail edit view controller managed by STV and I have manually inserted a SCSwitchCell into the table view. When the user changes the switch to ON I would like a SCTextFieldCell to appear below the SCSwitchCell allowing the user to enter data. Likewise, when the user changes the switch to OFF I would like the SCTextFieldCell to disappear. I would also like the appearance and disappearance of the SCTextFieldCell to happen with a standard UITableViewRowAnimation. What is the best way to achieve this behaviour?

Thanks,
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: Animated appearance and disappearance of row 1 year, 4 months ago #2

Hi Tarek,

I was just about to ask a similiar question. I'd like to do the same but I'd also like to create an SCSection that has an embedded 'toggle' SCTableViewCell, eg. "More Detail", that when selected will expand the section displaying all of it's cells and the 'toggle' cell now displaying eg. "Less Detail". When the 'toggle cell is selected again the section collapses to just the 'toggle' cell again.

The row animation is the tricky part being that it needs to be part of STV.

Gary
  • panamind
  • OFFLINE
  • Senior Boarder
  • Posts: 77
  • Karma: 4

Re: Animated appearance and disappearance of row 1 year, 4 months ago #3

Come to think of it, this would be a terrific enhancement. What I would like to do with it is to present a subset of available rows in the detail initially, and expand the table to reveal more when necessary depending on the fields into which the user actually enters data. So, unless a 'major' field bound to the "Title" attribute (for example) is activated for editing by the user, the row(s) and 'minor' fields for other 'sub' attributes (e.g. siblings of the "Title" attribute such as "Author", "ISBN") remain out of sight.

I would test First-Responder in the 'major' field and then animate the reveal of the associated 'minor' attribute rows if the user is working there. And of course there would be a way of suppressing the visibility of content-less rows, on both the initial Edit dsiplay of the entity and each didEndEditing as the user progressed through the form -- making for a tight, clean form for the user. The animations would be a nice user feedback -- the form opens up for input dynamically as the user moves through it and closes up around only the information the user actually enters.

This also allows better MVC compliance as there can be less jiggering of the data model behind the scenes to structure the entity just for the sake of representation and usability -- a conceptually complex entity can itself be rather flat in the data model (without a lot of trivial one-to-one sub-entity setups) since the (virtual) hierarchy of the attributes is represented entirely in the (dynamic) display.

This would be sweet.
  • Geoffrey
  • OFFLINE
  • Senior Boarder
  • Posts: 48
  • Karma: 3

Re: Animated appearance and disappearance of row 1 year, 4 months ago #4

Thanks guys for the fantastic discussion.

Let me answer Matthew's question first (and Gary's too to a big extent).


When the user changes the switch to ON I would like a SCTextFieldCell to appear below the SCSwitchCell allowing the user to enter data. Likewise, when the user changes the switch to OFF I would like the SCTextFieldCell to disappear.


All the code below assumes that:
1- Your object has a property called "switchPropertyName" for the SCSwitchCell.
2- Your object has a property called "textPropertyName" for the SCTextFieldCell.
3- Both properties are included in the class definition (auto generated), and the text field cell comes right under the switch cell.

First, assuming that the switch cell is in an automatically generated detail view, I'll hide the text field if the initial value of the switch is off in detailViewWillAppear:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
// Enable delegate methods to get called for the detail model (e.g. valueChangedForRowAtIndexPath)
detailTableViewModel.delegate = self;
 
SCObjectSection *section = (SCObjectSection *)[detailTableViewModel sectionAtIndex:0];
SCSwitchCell *switchCell = (SCSwitchCell *)[section cellForPropertyName:@"switchPropertyName"];
 
if(switchCell.switchControl.on == FALSE)
{
// remove the text field cell (assuming it's right under the switch cell)
NSInteger index = [section indexForCell:switchCell];
[section removeCellAtIndex:index+1];
}
}
 


Now once the table is loaded, I'll need to detect whenever the switch value changes in valueChangedForRowAtIndexPath:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
valueChangedForRowAtIndexPath:(NSIndexPath *)indexPath
{
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
if([cell isKindOfClass:[SCSwitchCell class]])
{
SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
if( ((SCSwitchCell *)cell).switchControl.on )
{
SCTextFieldCell *textFieldCell = [SCTextFieldCell cellWithText:@"Enter Text" withPlaceholder:nil
withBoundObject:cell.boundObject withTextFieldTextPropertyName:@"textPropertyName"];
[section insertCell:textFieldCell atIndex:indexPath.row+1];
}
else
{
[section removeCellAtIndex:indexPath.row+1];
}
}
 
// reload the section
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:indexPath.section];
[tableViewModel.modeledTableView reloadSections:indexSet
withRowAnimation:UITableViewRowAnimationBottom];
}
 


Gary: You only need to implement the second part of the code, in the tableViewModel:didSelectRowAtIndexPath: method. Instead of testing switchControl.on, you'll create a BOOL variable that you'll toggle whenever the cell gets selected.

Hope this helps guys!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Last Edit: 1 year, 4 months ago by tarekskr.
The following user(s) said Thank You: jeanfabre

Re: Animated appearance and disappearance of row 1 year, 4 months ago #5

Hi Gary and Geoffrey,

This is already on our feature requests! Although it won't appear in STV 2.0 (launch already behind schedule!), it's very likely to be in 2.1. What we need to do is study the best way to tell STV about the cell hierarchy (of course your ideas are more than welcome). In addition, we need to come up with a set of actions that can happen for the child cells to appear (e.g. cellSelected, cellValueChanged, etc.).

I'll update you as soon as we have something in the works. Thanks again guys for all the ideas!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Animated appearance and disappearance of row 1 year, 4 months ago #6

Thanks Tarek. This worked great

Best wishes,
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2
Time to create page: 3.42 seconds