UA-17470720-3

Jump to content


Photo
- - - - -

Custom detail view


  • Please log in to reply
16 replies to this topic

#1 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 24 October 2010 - 04:52 PM

Hi,

I have based my app on the iPad sample app which is working great. Thanks! Since I need to create some custom cells (which wont be available until the next version) I want to be able to launch my own custom detail view from within the DetailViewController when one of my Sensible table cells is selected. That new class will handle any CoreData updates etc. What is the best way to launch this new DetailViewController2 from within the DetailViewController ??

Do I place Sensible delegates in my existing DetailViewController and then call the customDetailTableViewModelForRowAtIndexPath again ?? I'm a bit lost. Any help will be appreciated.

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 25 October 2010 - 05:39 AM

Hi Phil,

Just a clarification: in your iPad sample based application, do you want to load your custom detail view for a cell that exists in the RootViewController, or is it for a cell that exists in the DetailViewController?

#3 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 25 October 2010 - 02:03 PM

Hi,

It's for a cell in the DetailViewController

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 25 October 2010 - 05:02 PM

This should be very straight forward if you use our SCViewController or SCTableViewController classes. For a detailed example on doing this, please check out our implementation of SCDateCell's didSelectCell method (please ignore the part where it says "Check for custom detail view controller").

Please tell me if you're still having any questions regarding this.

#5 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 25 October 2010 - 07:16 PM

Hi,

I had a look at SCDateCell. I'm a bit confused though. Are you saying I should implement a class similiar to that ??

Is it setup via the detailViewWillAppearForCell method ?

I just need something to allow me to call my own view controller when a Cell is selected if possible ?

I'm sure its possible via the Sensible framework, I'm must be just missing something :)

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 26 October 2010 - 04:03 PM

I can give you a full code sample if you can give me a more exact idea about what the cell is and what exactly is the detail view controller composed of. This should make it a lot easier for you :)

#7 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 26 October 2010 - 04:49 PM

Cool thanks. My project is being run for both iPhone and iPad. Basically an Inspection can have multiple Areas associated with it. The cut down code is as follows :

// Create a class definition for TaskEntity
self.inspectionDefnArray = [NSArray @"address", @"areas", nil];

inspectionDef =
[SCClassDefinition definitionWithEntityName:@"Inspection" withManagedObjectContext:managedObjectContext withPropertyNames:inspectionDefnArray];
inspectionDef.uiElementDelegate = self;
inspectionDef.descriptionPropertyName = @"inspectionType.name";

SCClassDefinition *inspectorDef =
[SCClassDefinition definitionWithEntityName:@"Inspector" withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"name", nil]];

SCClassDefinition *areaDef =
[SCClassDefinition definitionWithEntityName:@"Area" withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"areaDescription", nil]];
areaDef.uiElementDelegate = self;
areaDef.titlePropertyName = @"areaDescription";

// Create InspectionArea class definition
SCClassDefinition *inspectionAreaClassDef =
[SCClassDefinition definitionWithEntityName:@"InspectionArea" withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects: @"area", @"notes",nil]];
[inspectionAreaClassDef propertyDefinitionWithName:@"notes"].type = SCPropertyTypeTextView;
inspectionAreaClassDef.uiElementDelegate = self;
inspectionAreaClassDef.keyPropertyName = @"area.areaDescription";
inspectionAreaClassDef.descriptionPropertyName = @"notes";
...
tableModel = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView withViewController:self
withEntityClassDefinition:inspectionDef];

then :
- (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]]) {
self.currentInspection = (Inspection*)managedObject;
}
}
return detailModel;
}

Basically its all working all good and working. See Pic Posted Image

However since my RootViewContrller is becoming a bit bit big/unmanageable and I need to incorporate some custom TextViews (which isn't available yet?), I want to break out the showing/update of the Area into its own DetailViewController. If that model can be handled by Sensible then thats ok but I'm happy with handling any CoreData work myself. Ultimately I need the tableview to accomodate custom INLINE editable UITextViews and for the Add item to be a PopoverController (on iPad) instead of the current UIModalPresentationStyle so that the user doesnt have to navigate multiple screens and its all selfcontained in one view.

As usual thanks for all your help.

#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 October 2010 - 10:49 AM

Hi Phil,

If I now understand you correctly, all you need is add an SCObjectCell, and Sensible TableView will do all the detail view work automatically for you.

The cell would simply be declared as follows:

...
SCObjectCell *inspectionAreaCell = [SCObjectCell cellWithBoundObject:self.currentInspection 
  withClassDefinition:inspectionAreaClassDef];
...

When this cell is tapped, it will automatically generate a detail view for you where you'll have two fields, "Area" and "Notes", as per your class definition.

Hope this is what you're looking for, please do not hesitate to discuss this further.

#9 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 27 October 2010 - 02:48 PM

Hi,

I'm not sure if I get you though. Where is that code called from ?? Is it added to my tableModel ?? or do I add it to the willDisplayCell ??

Thanks.

#10 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 October 2010 - 03:23 PM

It all depends on which model you need to add the cell to. If you're interested in adding it to the main model, then you should do it normally at viewDidLoad. If you're interested in adding it to a detail model, then you should do it in the tableViewModel:detailViewWillAppearForRowAtIndexPath:withDetailTableViewModel: method.

- (void)tableViewModel:(SCTableViewModel *)tableViewModel 
  detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
  withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
  SCObjectCell *inspectionAreaCell = [SCObjectCell cellWithBoundObject:self.currentInspection 
  withClassDefinition:inspectionAreaClassDef];

  [[detailTableViewModel sectionAtIndex:0] addCell:inspectionAreaCell];
}

Again, I'll be glad to help if this is still unclear.

#11 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 27 October 2010 - 03:44 PM

Hi,

Thanks for the code sample. It looks like that may help if I was wanting to add it to an auto generated detail view however I want the ability to launch my own ViewController if thats possible to handle the editing of that CoreData. As mentioned before my iPad version of the RootViewController is already calling a DetailViewController through the customDetail method, however I want the ability to call another detailview controller for this inspectionAreaCell ??

Sorry for the confusion, I'm probably not explaining myself very well :)

#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 October 2010 - 04:11 PM

Where do you want to launch your detail view from? :) As I am reviewing your first reply to this thread, I find that you need to have the cell that will launch the detail view be in another auto generated detail view. Is that correct?

To cut out all confusion, please let me summarize all your options:

*Option 1* Generate the detail view from a cell on your main model: just add an SCObjectCell to a section of your main model in your view controller's viewDidLoad method.

*Option 2* Generate the detail view from an automatically generated detail view: please check the code sample in my previous post.

*Option 3* Generate the detail view from scratch, by tapping a button for example: Create your view controller normally, add an SCTableViewModel to it (again as you would normally do), then add an SCObjectSection to the model:

...
SCObjectSection *objectSection = [SCObjectSection sectionWithHeaderTitle:nil
  withBoundObject:myInspectionAreaObject withClassDefinition:inspectionAreaClassDef];
[tableModel addSection:objectSection];
...

Please tell me if there is another option that you need to do.

#13 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 27 October 2010 - 05:12 PM

Ahh. That might be the confusion then. I need Option 3 in this case, since I want to create a detail view from scratch, and bypass the auto generated detail view.

As an analogy, in the iPad Sample app you have the Task Steps cell. I want to be able to launch my own (non auto generated) DetailView from that cell selection instead of the auto generated view.

#14 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 October 2010 - 05:32 PM

The "Task Steps" cell is an automatically generated SCArrayOfObjectsCell. To override its automatically generated detail view, just set its "allowEditDetailView" property to FALSE (you can do that in tableViewModel:willConfigureCell:forRowAtIndexPath:), then implement the tableViewModel:didSelectRowAtIndexPath: method and provide your custom view controller there.

#15 Lacroix

Lacroix

    Starting Out

  • STV 5.0 Pro
  • Pip
  • 5 posts
Reputation: 0
Neutral

Posted 03 February 2011 - 05:03 AM

Hi Tarek,

It would be great to have a sample for this.

Many thanks in advance !

#16 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 February 2011 - 12:49 PM

Hi Lacroix,

I apologize for the delayed response as I was in the midst of the crisis in Egypt.

In STV 2.0 (currently available as RC, final version release date to be announced soon), there is a sample application called "Custom View App" that shows this in detail. Please send us on our support email if you don't currently have our STV 2.0 RC.

#17 Phil

Phil

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 138 posts
Reputation: 7
Good

Posted 15 February 2011 - 06:40 PM

HI Tarek,

I hope you are safe now then!

I am just getting back into the next version for my iPad project so could I get access to STV 2.0 RC.

Thanks,
Phil.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users