UA-17470720-3

Jump to content


Photo
- - - - -

ObjectSelection with custom detailViewController

models sections view-controllers core-data actions

  • Please log in to reply
6 replies to this topic

#1 Alexander Ekdahl

Alexander Ekdahl

    Starting Out

  • STV 4.0 Pro
  • Pip
  • 2 posts
Reputation: 2
Good

Posted 05 March 2013 - 08:04 AM

Hi,

First post on the forum :)

I have an issue with an objectselection and its detailview. Since there are a number of values to chose from in the detail view I need a way to structure it and make it easy for the user to find the right one. In other words I need a search feature or an index. Usually, this is easy to accomplish using the SCArrayofObjectsModel, but since, this one is inside an automatically loaded detailview it seems to be much harder.

I did try to load a custom detail view (see code below) but I can't get it to return a value that the main view accepts.

I think I've tried everything but I can't get it right. I would appreciate if someone could point me in the right direction or, even better, provide me some easy code example on how to bind the selected object on detail view to the objectSelectionCell on the main view.

main.h
@class DetailView;

@interface ObjectiveWizard : SCViewController <SCTableViewControllerDelegate,SCTableViewModelDataSource,SCTableViewModelDelegate>

@property (strong, nonatomic) DetailView *detailView;

@end


main.m (the interesting parts)
SCPropertyDefinition *myProperty = [entityPropDef propertyDefinitionWithName:@"property"];
myProperty.type = SCPropertyTypeObjectSelection;
SCObjectSelectionAttributes *attr = [SCObjectSelectionAttributes attributesWithObjectsEntityDefinition:secondEntityList usingPredicate:nil allowMultipleSelection:NO allowNoSelection:NO];
attr.autoDismissDetailView = YES;
attr.allowAddingItems = YES;
myProperty.attributes = attr;
myProperty.required = YES;

myProperty.cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 DetailView *customVC = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
	
	 return customVC;
};


SCArrayOfObjectsSection *section = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil entityDefinition:entityPropDef];
section.allowEditDetailView = YES;
section.allowAddingItems = YES;
section.allowDeletingItems = YES;
section.allowMovingItems = NO;

And DetailView.h
#import "MainView.h"
@interface DetailView : SCViewController <SCTableViewControllerDelegate,SCTableViewModelDataSource,SCTableViewModelDelegate>
@end

DetailView.m
- (void)viewDidLoad
{
[super viewDidLoad];
............
............

self.navigationBarType = SCNavigationBarTypeDoneRightCancelLeft;

SCSelectionModel *selectionModel = [[SCSelectionModel alloc] initWithTableView:self.tableView entityDefinition:secondEntityList filterPredicate:nil];
selectionModel.autoSortSections = TRUE;
selectionModel.allowAddingItems = YES;
selectionModel.allowDeletingItems = YES;
selectionModel.allowMovingItems = NO;
selectionModel.allowEditDetailView = NO;
selectionModel.modelActions.sectionHeaderTitleForItem = ^NSString*(SCArrayOfItemsModel *itemsModel, NSObject *item, NSUInteger itemIndex) {
	
....
Header titles
....
	 return [objectName capitalizedString];
};

self.tableViewModel = selectionModel;
}


The custom detailViewcontroller gets called and filled with values, but I can't return from that view in any other way than to press cancel. If I select a value and press done, the app crash with a "unrecognized selector" error (seems to be due to selectedItemsindex.

If anyone could guide me on how to accomplish this i would really appreciate it!

Thank you for your time!

Alex

Edited by Alexander Ekdahl, 05 March 2013 - 08:06 AM.

  • poffel likes this

#2 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 05 March 2013 - 12:08 PM

+1 on this question, looking for same info.

#3 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 05 March 2013 - 12:37 PM

lol, i just had this issue discussed with Tarek yesterday and he asked me to post this question here in the forum. But you where faster :-)

Edited by Lars Kohlmorgen, 05 March 2013 - 12:37 PM.


#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 06 March 2013 - 05:47 PM

Hi Alexander and welcome to our forums! :)

Since this is apparently becoming a popular request, I think it's best to add an SCObjectSelectionModel to STV ASAP. I can give you guys a beta version of STV 3.2.0 in a couple of weeks time, would that be ok?

Once you have an SCObjectSelectionModel, all you need would be to pass it to STV to use instead of it's automatically generated SCTableViewModel & SCObjectSelectionSection combo. Your code will look like this:

myProperty.cellActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewCell *cell, NSIndexPath *indexPath)
{
   return [[SCObjectSelectionModel alloc] init];
};

That's it, STV will take care of everything else! Please note that if you do need search functionality (not just an index), then you'll need to add a search bar like we did in PeopleViewController.xib (Core Data App sample), and use cellActions.detailViewController instead of cellActions.detailTableViewModel:

myProperty.cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath)
{
  MyCustomViewController *customVC = [[MyCustomViewController alloc] initWithNib:@"MyCustomViewController" bundle:nil];

  SCObjectSelectionModel *objectSelectionModel = [[SCObjectSelectionModel alloc] init];
  objectSelectionModel.searchBar = customVC.searchBar;
  customVC.tableViewModel = objectSelectionModel;

  return customVC;
};

STV 3.2.0 will also support UISearchDisplayController out of the box, so you can also create that. We will demonstrate how to do this in a sample app once 3.2.0 has been released.
  • cometlinear likes this

#5 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 06 March 2013 - 06:46 PM

Hi Tarek,
I think the examples will clear things up. I thought I was looking for the same functionality as described by Alexander and Lars, but I'm not quite sure now. I have been trying to figure out how to make a custom view controller act just like a generated detail view controller in the sense of updating the model - in a protocol/delegate fashion but of course without them.

these examples may seem contrived but just trying to explain my question.

- say we wanted to use a custom view controller to replace a string selection detail view. How would we pass the selected item(s) back into the model?
- same for any object. Granted, the need is not as great, but it would be a great example to see how to emulate any of the crud style detail views, in the event we need to do something more custom.
creating one is pretty easy, just updating the model on the way back is not so clear.

as always, thanks Tarek!
Ev

#6 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 07 March 2013 - 12:35 AM

It's really nice that we will get an out of the box functionality with STV 3.2 for this case, but can you please share with us how to achieve this on a self-implemented basis, Tarek? ;-) I am stuck getting my customViewcontroller displayed in the didSelect action...

#7 Alexander Ekdahl

Alexander Ekdahl

    Starting Out

  • STV 4.0 Pro
  • Pip
  • 2 posts
Reputation: 2
Good

Posted 07 March 2013 - 12:44 AM

Hi Tarek,

Thank you!
I can wait for an STV 3.2.0 beta if I can get the functionality out of the box.
A couple of weeks waiting won't be a problem, but do you have a closer estimate on when it will be available?

If we stay on schedule, we plan to enter test phase of our app end of march, so a week before that would be great! :)

Thanks again!





Also tagged with one or more of these keywords: models, sections, view-controllers, core-data, actions

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users