Welcome, Guest
Username Password: Remember me

Validating detail views in SCArrayOfObjectsSection.
(1 viewing) (1) Guest

TOPIC: Validating detail views in SCArrayOfObjectsSection.

Validating detail views in SCArrayOfObjectsSection. 1 year, 2 months ago #1

I have an SCArrayOfOjects section that allows the user to manage tags.

The user can swipe right to delete or press Edit, they can also press the 'Add' button and the detail view is bought up. The detail view allows the user to enter the name for the new tag.

The issue is that there are certain characters that the user shouldn't be putting into the tag name and I don't want to allow duplicate tag names.

So what I'd like is to be notified when the user has finished editing a tag name or just before the tag is added to the Managed Object Context.

I did some research in these forums and found a post about validating objects ( www.sensiblecocoa.com/forum/sensible-tab...t=6&start=6#1672 ).

I was happy and so I added a tableViewModel:detailViewWillAppearForRowAtIndexPath:withDetailTableViewModel: handler, where I set the delagate of the new model to self and then added a tableViewModel:tableViewModelvalueIsValidForRowAtIndexPath: handler.

I expected the second hander to be called as the detail view is edited or dismissed but it seems to be called just before the detail view is presented so it won't serve my purposes.

What's the best way to do what I want to do?

STV handles everything so well I feel like I'm missing something simple!
  • oldbeamer
  • OFFLINE
  • Junior Boarder
  • Posts: 37
  • Karma: 0

Re: Validating detail views in SCArrayOfObjectsSection. 1 year, 2 months ago #2

You're almost there! You just need to specify which properties in the class definition should be manually validated by setting their "autoValidate" property to FALSE.

Also, here is another post that can save you some code since it uses SCTableViewCellDelegate methods directly instead: www.sensiblecocoa.com/forum/sensible-tab...p-property.html#2104

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

Re: Validating detail views in SCArrayOfObjectsSection. 1 year, 2 months ago #3

Hi Tarek, thank you again for your time.

I WAS setting autoValidate to FALSE.

Still am! but it's still not working for me. I even tried the delegate methods you mentioned in your previous message and they don't get called either.

Is the autovalidate functionality for Core Data objects relatively new? Could it be I'm running an older version of STV? I didn't think I was BUT ...

When I look at my code the autoValidate attribute for my property definition isn't displayed in yellow, it's white. 'title' and 'type' both are displayed in yellow.

I've had a look at your code and autoValidate is all over it but could it be that my version doesn't work with Core Data? Did you have any issues around this functionality?

Sorry to continue to not get this right.
  • oldbeamer
  • OFFLINE
  • Junior Boarder
  • Posts: 37
  • Karma: 0

Re: Validating detail views in SCArrayOfObjectsSection. 1 year, 2 months ago #4

Hi Emiliano,

Are you able to post your code (or send me your project file if you wish) so that I would be able to take a closer look a this? Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Validating detail views in SCArrayOfObjectsSection. 1 year, 2 months ago #5

Of course Tarek, here are the relevant bits:

Header file:
 
@interface OptionsViewController : UIViewController <SCTableViewModelDelegate,SCTableViewCellDelegate>{
IBOutlet UITableView *table;
SCTableViewModel *tableModel;
SCArrayOfObjectsSection *objectsSection;
}
 
@property (nonatomic,retain) UITableView *table;
@property (nonatomic,retain) SCTableViewModel *tableModel;
@property (nonatomic,retain) SCArrayOfObjectsSection *objectsSection;
 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel detailViewWillAppearForRowAtIndexPath:(NSIndexPath *) indexPath withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel;
- (BOOL)tableViewModel:(SCTableViewModel *) tableViewModel valueIsValidForRowAtIndexPath:(NSIndexPath *) indexPath;
- (BOOL)valueIsValidForCell:(SCTableViewCell *)cell;
 
@end
 


Implementation:

 
 
-(void)viewDidLoad{
[super viewDidLoad];
 
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
 
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
 
// Instantiate the tabel model
self.tableModel = [[SCTableViewModel alloc] initWithTableView:self.table withViewController:self];
self.tableModel.editButtonItem = self.navigationItem.leftBarButtonItem;
self.tableModel.delegate=self;
 
// Get managedObjectContext from application delegate
NSManagedObjectContext *managedObjectContext = [DataController sharedDataController].managedObjectContext;
 
 
SCClassDefinition *tagClassDefinition =
[SCClassDefinition definitionWithEntityName:@"Tag" withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"name", nil]];
 
 
// Do some property definition customization
SCPropertyDefinition *tagPropertyDef = [tagClassDefinition propertyDefinitionWithName:@"name"];
tagPropertyDef.title = @"Tag name";
tagPropertyDef.type = SCPropertyTypeTextField;
tagPropertyDef.autoValidate=FALSE;
 
 
// Create and add the objects section
self.objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
withEntityClassDefinition:tagClassDefinition];
self.objectsSection.detailViewModalPresentationStyle= UIModalPresentationCurrentContext;
self.objectsSection.addButtonItem = self.navigationItem.rightBarButtonItem;
[tableModel addSection:self.objectsSection];
 
}
 
-(void)viewWillAppear:(BOOL)animated{
 
[tableModel reloadBoundValues];
[tableModel.modeledTableView reloadData];
 
}
 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel detailViewWillAppearForRowAtIndexPath:(NSIndexPath *) indexPath withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel{
 
NSLog(@"detail view will appear with indexpath %@",indexPath);
detailTableViewModel.delegate=self;
 
}
 
 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath{
cell.height=50;
cell.textLabel.font=[UIFont fontWithName:@"Helvetica" size:18];
cell.textLabel.textColor=[UIColor colorWithWhite:0.3 alpha:1.0];
 
}
 
- (BOOL)valueIsValidForCell:(SCTableViewCell *)cell
{
NSLog(@"checking validity of cell %@",cell);
return YES;
}
 
- (BOOL)tableViewModel:(SCTableViewModel *) tableViewModel valueIsValidForRowAtIndexPath:(NSIndexPath *) indexPath{
NSLog(@"checking valididty of %@",indexPath);
return YES;
}
 
 
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
 
 
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
 
// Release any cached data, images, etc that aren't in use.
}
 
 
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
 
 
- (void)dealloc {
[super dealloc];
}
 
  • oldbeamer
  • OFFLINE
  • Junior Boarder
  • Posts: 37
  • Karma: 0

Re: Validating detail views in SCArrayOfObjectsSection. 1 year, 2 months ago #6

Hi Emiliano,

You should not declare the delegate methods in the interface section. If you choose to implement the SCTableViewCellDelegate methods, you interface should look something like this:

 
@interface OptionsViewController : UIViewController <SCTableViewCellDelegate>{
IBOutlet UITableView *table;
SCTableViewModel *tableModel;
SCArrayOfObjectsSection *objectsSection;
}
 
@property (nonatomic,retain) UITableView *table;
@property (nonatomic,retain) SCTableViewModel *tableModel;
@property (nonatomic,retain) SCArrayOfObjectsSection *objectsSection;
 
@end
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Time to create page: 1.22 seconds