UA-17470720-3

Jump to content


Photo
- - - - -

cellActions for a Core Data entity that is set to expandContentInCurrentView

core-data general

  • Please log in to reply
2 replies to this topic

#1 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 22 October 2012 - 09:39 AM

Hi All,

I've been struggling with this all day, so hopefully someone can point me in the right direction.....

I have a Core Data entity BikeEntity that I can then add multiple videos to, each video being a VideoEntity. Here's some STV code:


NSManagedObjectContext *managedObjectContext = [(id)[UIApplication sharedApplication].delegate managedObjectContext];

///////////////////////////////////////////////////////////////////////////////////////////
// the below should go when the custom property definition using ~ works for
// Core Data entities in STV 3.1.3 see:
// http://sensiblecocoa.com/community/topic/1346-custom-property-definition-using-tilde/#entry7166
//

SCCustomPropertyDefinition *buttonPropertyDef = [SCCustomPropertyDefinition definitionWithName:@"button" uiElementClass:[SCTableViewCell class] objectBindingsString:nil];
buttonPropertyDef.existsInCreationMode = NO;
buttonPropertyDef.existsInEditingMode = YES;
buttonPropertyDef.existsInDetailMode = YES;
buttonPropertyDef.existsInNormalMode = NO;

buttonPropertyDef.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 cell.textLabel.textAlignment = NSTextAlignmentCenter;
	 cell.textLabel.text =@"Add a video...";
};

buttonPropertyDef.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 // only get's fired when the table is in edit mode
	 VideoCaptureViewController *videoCaptureViewController = [[VideoCaptureViewController alloc] initWithNibName:@"VideoCaptureView" bundle:nil];
	 videoCaptureViewController.title = @"";
	 [self.navigationController pushViewController:videoCaptureViewController animated:YES];
};

//////////////////////////////////////////////////////////////////////////////////////////


// Create an entity definition for VideoEntity
SCEntityDefinition *videoEntityDefinition = [SCEntityDefinition definitionWithEntityName:@"VideoEntity" managedObjectContext:managedObjectContext propertyNamesString:@"videoName;videoDescription"];
videoEntityDefinition.requireEditingModeToEditPropertyValues = YES;
videoEntityDefinition.orderAttributeName = @"videoOrder";

SCPropertyDefinition *videoNamePropertyDefinition = [videoEntityDefinition propertyDefinitionWithName:@"videoName"];
videoNamePropertyDefinition.title = @"Name";

SCPropertyDefinition *videoDescriptionPropertyDefinition = [videoEntityDefinition propertyDefinitionWithName:@"videoDescription"];
videoDescriptionPropertyDefinition.title = @"Notes";
videoDescriptionPropertyDefinition.type = SCPropertyTypeTextView;

videoEntityDefinition.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 NSLog(@"videoEntityDefinition didSelect"); // never logged
};

videoEntityDefinition.cellActions.detailViewController = ^SCViewController*(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 NSLog(@"videoEntityDefinition didSelect"); // never logged
	 return nil;
};


// Create an entity definition for BikeEntity
SCEntityDefinition *bikeEntityDefinition = [SCEntityDefinition definitionWithEntityName:@"BikeEntity" managedObjectContext:managedObjectContext propertyNamesString:@":(bikeName);:(video)"];
bikeEntityDefinition.orderAttributeName = @"bikeOrder";
bikeEntityDefinition.requireEditingModeToEditPropertyValues = YES;


[bikeEntityDefinition addPropertyDefinition:buttonPropertyDef];

SCPropertyDefinition *namePropertyDefinition = [bikeEntityDefinition propertyDefinitionWithName:@"bikeName"];
namePropertyDefinition.title = @"Name";
namePropertyDefinition.required = YES;
namePropertyDefinition.existsInCreationMode = YES;
namePropertyDefinition.existsInEditingMode = YES;
namePropertyDefinition.existsInNormalMode = NO;
namePropertyDefinition.existsInDetailMode = YES;

SCArrayOfObjectsSection *bikesArrayOfObjectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil entityDefinition:bikeEntityDefinition];
bikesArrayOfObjectsSection.placeholderCell = [SCTableViewCell cellWithText:@"No bikes!" textAlignment:NSTextAlignmentCenter];

bikesArrayOfObjectsSection.addNewItemCell = [SCTableViewCell cellWithText:@"Add a bike..."];
bikesArrayOfObjectsSection.addNewItemCellExistsInNormalMode = YES;
bikesArrayOfObjectsSection.addNewItemCellExistsInEditingMode = YES;

bikesArrayOfObjectsSection.allowRowSelection = YES;
bikesArrayOfObjectsSection.allowAddingItems = YES;
bikesArrayOfObjectsSection.allowDeletingItems = YES;
bikesArrayOfObjectsSection.allowMovingItems = YES;
bikesArrayOfObjectsSection.allowEditDetailView = YES;
bikesArrayOfObjectsSection.autoSelectNewItemCell = YES;
bikesArrayOfObjectsSection.skipNewItemDetailView = NO;
bikesArrayOfObjectsSection.itemsAccessoryType = UITableViewCellAccessoryDisclosureIndicator;



SCPropertyDefinition *videoPropertyDefinition = [bikeEntityDefinition propertyDefinitionWithName:@"video"];
videoPropertyDefinition.attributes = [SCArrayOfObjectsAttributes attributesWithObjectDefinition:videoEntityDefinition
allowAddingItems:NO
allowDeletingItems:YES
allowMovingItems:NO
expandContentInCurrentView:YES
placeholderuiElement:[SCTableViewCell cellWithText:@"Edit to add a video"]
addNewObjectuiElement:nil
addNewObjectuiElementExistsInNormalMode:NO
addNewObjectuiElementExistsInEditingMode:NO];

videoPropertyDefinition.existsInCreationMode = NO;
videoPropertyDefinition.existsInEditingMode = YES;
videoPropertyDefinition.existsInNormalMode = NO;
videoPropertyDefinition.existsInDetailMode = YES;



videoPropertyDefinition.cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 NSLog(@"videoPropertyDefinition detailViewController"); // never logged
	 return nil;
};


bikesArrayOfObjectsSection.cellActions.willSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 NSLog(@"bikesArrayOfObjectsSection cellAction willSelect");
	 // used when updating Core Data with a new video file
	 self.currentBike = (BikeEntity *)cell.boundObject;
};

[self.tableViewModel addSection:bikesArrayOfObjectsSection];

So I have all the video names listed in a table section by expandContentInCurrentView:YES, great! When I select a cell with a video name what cellAction or sectionAction or delegate method can I hook into to present my own view (to play the video)? None of the ones I've tired (and I think I've tried them all today!) is ever fired.

Thanks very much in advance for any help or pointers in the right direction.
  • David DelMonte likes this
Cheers,

Dave

www.dgapps.ie

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 23 October 2012 - 12:29 AM

Hi Dave,

Since the Video cells are part of an SCArrayOfObjectsSection, which is in turn is responsible for the detail views, you should be implementing sectionAction(s) instead of cellAction(s). The cells in an SCArrayOfObjectsSection are typically simple SCTableViewCells and have no idea about the generated detail views. The easiest way to access the section actions of the video entity in your case is via the videoPropertyDefinition attributes:

...
SCArrayOfObjectsAttributes *videoAttributes = [SCArrayOfObjectsAttributes attributesWithObjectDefinition:videoEntityDefinition
  allowAddingItems:NO
  allowDeletingItems:YES
  allowMovingItems:NO
  expandContentInCurrentView:YES
  placeholderuiElement:[SCTableViewCell cellWithText:@"Edit to add a video"]
  addNewObjectuiElement:nil
  addNewObjectuiElementExistsInNormalMode:NO
  addNewObjectuiElementExistsInEditingMode:NO];
videoAttributes.sectionActions..detailViewController = ^UIViewController*(SCTableViewSection *section, NSIndexPath *indexPath)
{
MyCustomViewController *customVC = [[MyCustomViewController alloc] initWithNib:@"MyCustomViewController" bundle:nil];
return customVC;
};
videoPropertyDefinition.attributes = videoAttributes;
...

Hope this helps!
  • David DelMonte likes this

#3 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 23 October 2012 - 01:50 AM

Hi Tarek,

Thank you, thank you, thank you!

I spent so long yesterday trying to work out what cellAction or sectionAction I needed to call and where. Thank you again for pointing me to the right bit!

As it's a sectionAction I needed to use detailViewControllerForRowAtIndexPath, detailViewController is a cellAction I think.

I'm sure I'll be back in a while with more questions, but for now thank you.
Cheers,

Dave

www.dgapps.ie





Also tagged with one or more of these keywords: core-data, general

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users