Welcome, Guest
Username Password: Remember me

Dynamically Creating Object Detail Views
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Dynamically Creating Object Detail Views

Dynamically Creating Object Detail Views 1 year, 6 months ago #1

One area where I'd appreciate your advice on the best approach is in generating dynamic objects.

By way of background the little demo I'm working on is to allow a user to configure a questionnaire. In one view I've got an SCPropertyTypeSelection cell where the user selects what type of question they want - text, numeric, date etc.

Next I wanted to use an SCObjectCell to allow the user to advance to a view of parameters for the configured response type, where they can configure criteria such as sub-type, validation format, min value, max value etc.

Issue is the available parameters will be a variable number and different type for each response type. In your samples you're setting up the hierarchy and property definitions all at once in the initial view's viewDidLoad. I'd really like to implement willSelectRowAtIndexPath or didSelectRowAtIndexPath for this object cell and dynamically setup the detail object then - using key binding or perhaps dictionary editing to define the object for the detail view.

I see SCObjectCell has an objectClassDefinition property but setting the bound object only appears in the initialisers. What would you suggest the best approach is?

On a related note we store the various parameters all as strings in the back end database. Is it possible to have an NSString object with a cell type set to something normally associated with an NSNumber like numeric text or slider - or will I need to implement custom accessors to achieve this?

Cheers,
Steve.
  • stevep
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 0

Re: Dynamically Creating Object Detail Views 1 year, 6 months ago #2

Thanks for the interesting question Steve.

The way to go about solving this is not by creating an SCObjectCell, but rather by creating a normal SCTableViewCell that will display a detail view with an SCObjectSection. The detail SCObjectSection will then be dynamically configured according to the value selected in your selection cell. Here is some sample code illustrating this:

 
- (void)viewDidLoad
{
...
// Add an extra cell to your main section
SCTableViewCell *parametersCell = [SCTableViewCell cellWithText:@"Question Parameters"];
parametersCell.tag = 101; // any tag
[mainSection addCell:parametersCell];
...
}
 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([tableModel cellAtIndexPath:indexPath].tag == 101)
{
// Create the detail view. I am here using an SCTableViewController because it's
// much more convenient to use than a UITableViewController. However, please feel
// free to use a normal UITableViewController if you wish.
SCTableViewController *detailViewController =
[[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped withNavigationBarType:SCNavigationBarTypeNone];
 
// Now generate the object section dynamically and add it to the detail model.
// myDynamicObject and myDynamicClassDef should be determined according to the
// selection made by the user in the selection cell.
SCObjectSection *objectSection =
[SCObjectSection sectionWithHeaderTitle:nil withBoundObject:myDynamicObject
withClassDefinition:myDynamicClassDef];
[detailViewController.tableViewModel addSection:objectSection];
 
// Finally, push the detail view (assuming you have a navigation controller configured)
[self.navigationController pushViewController:detailViewController animated:TRUE];
 
[detailViewController release];
}
}
 


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

Re: Dynamically Creating Object Detail Views 1 year, 6 months ago #3


On a related note we store the various parameters all as strings in the back end database. Is it possible to have an NSString object with a cell type set to something normally associated with an NSNumber like numeric text or slider - or will I need to implement custom accessors to achieve this?


STV cells should be always bound to properties with the correct type. For example, an SCSliderCell should only be bound to a property of NSNumber, and cannot be bound to an NSString for example. What you should do is bind the cells normally and then convert all the values to NSStrings before comitting them to your database.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Dynamically Creating Object Detail Views 1 year, 6 months ago #4

Thanks Tarek,

that's a nice concise solution which will be ideal for the job.

Cheers,
Steve.
  • stevep
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 0
  • Page:
  • 1
Time to create page: 1.62 seconds