UA-17470720-3

Jump to content


Photo
- - - - -

Core Data Storing an Image(not path) to be displayed in SensibleTableView

models sections cells view-controllers core-data

  • Please log in to reply
13 replies to this topic

#1 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 14 January 2015 - 08:42 AM

Is it possible to have SensibleTableView display an Image that's stored as Binary Data in Core Data? I looked around for an Image Picker sample but couldn't really find anything.

 

 

SCPropertyTypeImagePicker is working, but it saves only the local path instead of storing the full image as binary data.

 

My goal is to save image as a binary data (should sync in server too), so when ever i log in from any mobile using my credential, i want to see the saved image.

 

thanks,

bala

 

 



#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 January 2015 - 03:30 PM

Hi bala,

 

There are many ways to implement this, but the easiest is probably to keep using your SCPropertyTypeImagePicker, but then implement its cellActions.saveImage and cellActions.loadImage to manually save and load the image in whichever format you want. For example, your code could look something like this:

 

SCPropertyDefinition *imagePropertyDef = [myEntityDef propertyDefinitionWithName:@"myImagePropertyName"];
imagePropertyDef.cellActions.saveImage = ^(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
{
    UIImage *myImage = imagePickerCell.selectedImage;
    NSManagedObject *myCoreDataObject = (NSManagedObject *)imagePickerCell.boundObject;

    // Convert the myImage to binary here then write it in myCoreDataObject
};

imagePropertyDef.cellActions.loadImage = ^UIImage*(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
{
    NSManagedObject *myCoreDataObject = (NSManagedObject *)imagePickerCell.boundObject;

    // Read the image binary data here and convert it to UIImage

    return myImage;
};

 

 

Hope this helps.


  • David DelMonte and wizgod like this

#3 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 16 January 2015 - 06:46 AM

Thanks Tarek,

 

But your code throws error.

 

Property 'saveImage' not found on object of type 'SCCellActions *'

 

this is my code

 

 SCPropertyDefinition *imagePropertyDef = [documentDef propertyDefinitionWithName:@"image"];

    imagePropertyDef.type = SCPropertyTypeImagePicker;

    imagePropertyDef.title = @"Document";

    

    imagePropertyDef.cellActions.saveImage = ^(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)

    {

        UIImage *myImage = imagePickerCell.selectedImage;

        NSManagedObject *myCoreDataObject = (NSManagedObject *)imagePickerCell.boundObject;

        

        // Convert the myImage to binary here then write it in myCoreDataObject

    };



#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 16 January 2015 - 03:39 PM

Documentation says saveImage is for SCImagePickerCell.. so might have to do it a little different.. else STV has a little bug

try

    SCPropertyDefinition *imagePropertyDef = [documentDef propertyDefinitionWithName:@"image"];
    imagePropertyDef.type = SCPropertyTypeImagePicker;
    imagePropertyDef.title = @"Document";
    
    imagePropertyDef.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCImagePickerCell *pickerCell = (SCImagePickerCell*)cell;
        pickerCell.cellActions.saveImage = ^(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
        {
            UIImage *myImage = imagePickerCell.selectedImage;
            NSManagedObject *myCoreDataObject = (NSManagedObject *)imagePickerCell.boundObject;
            
            // Convert the myImage to binary here then write it in myCoreDataObject
        };

    };

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 17 January 2015 - 09:58 AM

Thanks Ozie,

 

its not helping. still it shows same error.

 

I am using STV 3.3, please let me know if there is any other way to achieve my requirement.

 

thanks,

bala.



#6 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 541 posts
  • LocationIreland
Reputation: 134
Popular

Posted 19 January 2015 - 02:50 AM

Hi Balachandhar,

 

With STV 3.x you'll be looking for the SCTableViewModelDelegate methods:

 

- (void)tableViewModel:(SCTableViewModel *)tableModel saveImage:(UIImage *)image toPath:(NSString *)path forRowAtIndexPath:(NSIndexPath *)indexPath

 

- (UIImage *)tableViewModel:(SCTableViewModel *)tableModel loadImageFromPath:(NSString *)path forRowAtIndexPath:(NSIndexPath *)indexPath
 
HTH

  • Tarek and David DelMonte like this
Cheers,

Dave

www.dgapps.ie

#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 January 2015 - 09:20 AM

Hi bala,

 

Sorry I didn't realize you were using STV 3.0. The above code only works for STV 4.0+.



#8 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 20 January 2015 - 01:34 AM

were should i download STV 4.0 ? i can able to see only STV 3.xx in the download page. 

 

is it possible in stove 3.xx version? 

 

thanks,

bala



#9 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 20 January 2015 - 01:39 AM

STV v4 is a paid update.. and well worth it:)

You wont be able to see it listed in the download page until you purchase it.. 


  • Tarek likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#10 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 20 January 2015 - 11:59 AM

Yes, it's possible with STV 3.x by using delegates, just as Dave has kindly mentioned above.



#11 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 23 January 2015 - 08:45 PM

Hi bala,

 

There are many ways to implement this, but the easiest is probably to keep using your SCPropertyTypeImagePicker, but then implement its cellActions.saveImage and cellActions.loadImage to manually save and load the image in whichever format you want. For example, your code could look something like this:

 

SCPropertyDefinition *imagePropertyDef = [myEntityDef propertyDefinitionWithName:@"myImagePropertyName"];
imagePropertyDef.cellActions.saveImage = ^(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
{
    UIImage *myImage = imagePickerCell.selectedImage;
    NSManagedObject *myCoreDataObject = (NSManagedObject *)imagePickerCell.boundObject;

    // Convert the myImage to binary here then write it in myCoreDataObject
};

imagePropertyDef.cellActions.loadImage = ^UIImage*(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
{
    NSManagedObject *myCoreDataObject = (NSManagedObject *)imagePickerCell.boundObject;

    // Read the image binary data here and convert it to UIImage

    return myImage;
};

 

 

Hope this helps.

 

 

Tarek.. i used this code today, and it seems that imagePickerCell.selectedImage is anyways NIL


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 26 January 2015 - 08:38 AM

Hi Ozie,

 

Perhaps you did not select an image yet?



#13 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 26 January 2015 - 08:13 PM

yeah.. the cell displays the image..but while debugging the object myImage is null


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#14 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 29 January 2015 - 04:10 PM

Thanks Ozie, fixed in 4.1.1.







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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users