UA-17470720-3

Jump to content


Photo
- - - - -

SCPropertyDefinition Required Autovalidate


  • Please log in to reply
8 replies to this topic

#1 Bryan Saltzman

Bryan Saltzman

    Experienced Member

  • STV 2.0
  • PipPipPipPip
  • 70 posts
Reputation: 0
Neutral

Posted 17 September 2010 - 09:11 AM

My application needs to make sure that the title of a row does not disappear, otherwise when the detail view naviagionController pushes a SCPropertyTypeSelection table, there is no title and hence no back button (stuck).

The code below allows me to edit my item and change myName to a blank string. How would I not allow the user to change myName to a blank string? I am binding to an array of objects.

SCPropertyDefinition *namePropertyDef = [shoeClassDef propertyDefinitionWithName:@"myName"];
namePropertyDef.type = SCPropertyTypeTextView;
namePropertyDef.title = @" ";
namePropertyDef.required = YES;
namePropertyDef.autoValidate = YES;


Thanks a lot

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 17 September 2010 - 10:46 AM

Hi Bryan:

Is this an auto generated detail view? Auto generated detail views will automatically disable the save button if a required value is empty. If the detail view is not auto generated, all you need to do is set the enabled property of your save button to SCTableViewModel "valuesAreValid" property whenever any value changes.

#3 Bryan Saltzman

Bryan Saltzman

    Experienced Member

  • STV 2.0
  • PipPipPipPip
  • 70 posts
Reputation: 0
Neutral

Posted 21 September 2010 - 04:09 AM

I don't have a save button.

Here is the code I am using:

- (void)tableViewModel:(SCTableViewModel *) tableViewModel detailViewWillAppearForRowAtIndexPath:(NSIndexPath *) indexPath withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel
{
	//Shoe *thisShoe = [tableData objectAtIndex:indexPath.row];
	Shoe *thisShoe = [[shoeIndexedArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
	
	
	SCTableViewSection *detailSection = [detailTableViewModel sectionAtIndex:0];
	SCTableViewCell *imagePickerCell = [detailSection cellAtIndex:0];
	imagePickerCell.imageView.image = [UIImage imageWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:[@"Documents/" stringByAppendingString:thisShoe.thumbName]]];
	
	
	//  Not working right now //////////////////////////
	UINavigationBar *detailNavBar = detailTableViewModel.viewController.navigationController.navigationBar;
	UINavigationItem  *detailNavItem = detailTableViewModel.viewController.navigationController.navigationItem;
	NSArray *statusItems = [[NSArray alloc] initWithObjects:@"Detail", @"Photo", nil];
	UISegmentedControl *photoNavSegment = [[UISegmentedControl alloc] initWithItems:statusItems];
	UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
	[myView addSubview:photoNavSegment];
	//UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:photoNavSegment] autorelease];
	detailNavItem.titleView = myView;
	//   end	////////////////////
	
	
	// Now add here any view you want to the navigation bar
	
	//imagePickerCell.textLabel.frame = CGRectMake(60, 10, 200, 60);
	//Shoe *myManagedObject = detailSection.boundObject;
	//
	// Set your managed object's attributes normally here
	NSLog(@"IDetwail will appear at Index");
	
}


#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 21 September 2010 - 05:17 AM

To have Sensible TableView generate a modal detail view (thus enforcing validation and generating a save button for you), just set the "detailViewModal" property of SCArrayOfObjectsSection to TRUE. Please tell me if I understand your problem correctly.

#5 Bryan Saltzman

Bryan Saltzman

    Experienced Member

  • STV 2.0
  • PipPipPipPip
  • 70 posts
Reputation: 0
Neutral

Posted 21 September 2010 - 12:33 PM

Excellent! Works perfectly :cheer:

#6 Bryan Saltzman

Bryan Saltzman

    Experienced Member

  • STV 2.0
  • PipPipPipPip
  • 70 posts
Reputation: 0
Neutral

Posted 21 September 2010 - 01:11 PM

That works great for editing, but it does not work for my add item screen because I am not using an ArrayOfObjects section but only one SCObjectSection.


Here is my code that could work, but I have a modalViewController in progress from an imagePicker, so this code crashes:

UINavigationController *detailNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
	 [self presentModalViewController:detailNavController animated:TRUE];

Here is all of it.

 - (void) loadNewObjectTable{
 
 SCNavigationBarType navBarType;
 if(self.navigationController)
 navBarType = SCNavigationBarTypeNone;
 else
 navBarType = SCNavigationBarTypeDoneRightCancelLeft;
 
 SCTableViewController *detailViewController = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped withNavigationBarType:navBarType];
 detailViewController.delegate = self;
 SCClassDefinition *shoeClassDef = [SCClassDefinition definitionWithClass:[Shoe class] 
 withPropertyNames:[mainDelegate attributeNamesArray]];
 
 [self setupClassWithDefinition:shoeClassDef];
 
 SCObjectSection *objSection = [SCObjectSection sectionWithHeaderTitle:nil withBoundObject:currentShoe withClassDefinition:shoeClassDef];

 [detailViewController.tableViewModel addSection:objSection];
 
	 
 if(self.navigationController)
 {
 [self.navigationController pushViewController:detailViewController animated:TRUE];
 }
 else
 {

// Create the navigation controller
 UINavigationController *detailNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
 [self presentModalViewController:detailNavController animated:TRUE];
 }
	 
	 
 [detailViewController release];
}
 


#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 22 September 2010 - 01:27 AM

I've tested the code you posted and it's working well...in fact it's really similar to the code we're using internally in SCArrayOfObjectsSection to add new objects. Are you able to send in your project to our support email for us to further investigate this? Thanks Bryan.

#8 Bryan Saltzman

Bryan Saltzman

    Experienced Member

  • STV 2.0
  • PipPipPipPip
  • 70 posts
Reputation: 0
Neutral

Posted 22 September 2010 - 01:56 AM

I am sending it now. Thanks Tarek!

#9 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 22 September 2010 - 12:12 PM

Just sent you back a modified version of your project. Is this what you're trying to accomplish Bryan?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users