Welcome, Guest
Username Password: Remember me

SCCustomPropertyDefinition boundPropertyName and value
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: SCCustomPropertyDefinition boundPropertyName and value

SCCustomPropertyDefinition boundPropertyName and value 1 year, 2 months ago #1

Hi

I've created a custom SCControlCell for picking photos. I know I could have used the built-in one for that, but my customer had a very specific look they wanted to achieve for this feature. So I created a custom cell for it and am using SCCustomPropertyDefinition to make it work.

I've implemented commitChanges and loadBoundValueIntoControl to setup and save the selected image. My boundValue is set to the image selected.

Now, in my view controller, I've implemented the valueChangedForRowAtIndexPath method. But when I put in a breakpoint, my boundValue is always nil. When I call self.boundValue = self.selectedPhoto, boundValue is nil immediately after the call. However, this is due to the fact that boundPropertyName is nil. I don't know why that's the case just yet.

This is how I'm configuring my custom cell:

 
 
NSDictionary *photoBindings = [NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:@"photo", nil]
forKeys:[NSArray arrayWithObjects:@"1", nil]]; // 1,2,3,4 are the control tags
dataProperty = [SCCustomPropertyDefinition definitionWithName:@"photo"
withuiElementNibName:@"PhotoSelectionCell"
withObjectBindings:photoBindings];
 
[classDef insertPropertyDefinition:dataProperty atIndex:8];
 


Thanks,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: SCCustomPropertyDefinition boundPropertyName and value 1 year, 2 months ago #2

Hi Brendan,

self.boundValue is reserved for storing the value of self.control, and thus requires that self.boundPropertyName be set too.

Taking a quick look at your case, I see that you've created a custom control instead (with tag=1), that binds itself the your object's "photo" property. In this case, you should be using the commitValueForControlWithTag method to store the control's value:

 
...
[self commitValueForControlWithTag:1 value:self.selectedPhoto];
...
 


Similarly, you should use boundValueForControlWithTag to retrieve the value back:

 
...
self.selectedPhoto = (UIImage *)[self boundValueForControlWithTag:1];
...
 


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

Re: SCCustomPropertyDefinition boundPropertyName and value 1 year, 2 months ago #3

Hi Tarek,

Ok, thanks for the tip. However, I get a warning trying to call [self commitValueForControlWithTag:1 value:self.selectedPhoto];

It says the method cannot be found. My custom cell subclasses SCControlCell.

warning: method '-commitValueForControlWithTag:value:' not found (return type defaults to 'id')


Here's my code on my PhotoSelectionCell subclass of SCControlCell:

 
//overrides superclass
- (void)loadBoundValueIntoControl {
 
pauseControlEvents = TRUE;
 
self.selectedPhoto = (UIImage *)[self boundValueForControlWithTag:1];
 
UIImage *thumbnail = [RPUtilities scale:80 andRotateImage:self.selectedPhoto];
[self.pickPhotoButton setImage:thumbnail forState:UIControlStateNormal];
 
pauseControlEvents = FALSE;
 
}
 
 
//overrides superclass
- (void)commitChanges
{
if(!self.needsCommit)
return;
 
[self commitValueForControlWithTag:1 value:self.selectedPhoto];
 
UIImage *thumbnail = [RPUtilities scale:80 andRotateImage:self.selectedPhoto];
[self.pickPhotoButton setImage:thumbnail forState:UIControlStateNormal];
 
//self.needsCommit = FALSE;
}
 
 
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
 
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
 
self.selectedPhoto = image;
 
[self cellValueChanged];
 
[picker dismissModalViewControllerAnimated:YES];
}
 
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: SCCustomPropertyDefinition boundPropertyName and value 1 year, 2 months ago #4

Ok, it turns out I had to import SCTableViewCell.h in my implementation as well as my header. I guess because that method isn't available in your header file.

Works now.

Thanks!

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: SCCustomPropertyDefinition boundPropertyName and value 1 year, 2 months ago #5

Actually I thought it worked, but it didn't. It turns out during my experimentation, I changed [self commitValueForControlWithTag:1 value:self.selectedPhoto]; to just [self commitChanges] and that made the warning go away. But that's not what I meant to do.
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: SCCustomPropertyDefinition boundPropertyName and value 1 year, 2 months ago #6

Apologies for that Brendan, it's actually my fault. It turns out that we defined commitValueForControlWithTag in a private category. We'll move it to the main class interface in our final release, which will solve your problem and is a better design decision. Until we launch STV 2.0 (expected during the next couple of days), you can just move the method declaration yourself from the private SCControlCell category to the main SCControlCell interface. Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.97 seconds