UA-17470720-3

Jump to content


Photo
- - - - -

Assign a SCImagePickerCell "Default Image"

data-stores models cells actions

  • Please log in to reply
6 replies to this topic

#1 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 04 January 2014 - 02:36 PM

Folks,

 

I want to assign a default image to a SCImagePickerCell and am struggling to do so. The default image only shows up which a new image is selected. Below is code:

 

myPropertyDef.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath)

    {

        if([cell isKindOfClass:[SCImagePickerCell class]])

        {

            PoleEntity *pole = (PoleEntity *)cell.boundObject;

            

            //Configure SCImagePickerCell Attributes

            SCImagePickerCell *imagePickerCell = (SCImagePickerCell *) cell;

            imagePickerCell.displayImageNameAsCellText = NO;

            imagePickerCell.displayClearImageButtonInDetailView = TRUE;

            imagePickerCell.imagePickerController.allowsEditing = YES;

            imagePickerCell.height = 100;

            imagePickerCell.imageViewFrame = CGRectMake(10, 10, 80, 80);

            imagePickerCell.placeholderImageName = @"test";

            imagePickerCell.placeholderImageTitle = @"";

            

            NSString *imageString = @"test";

            NSString *fullName = [NSString stringWithFormat:@"Documents/%@", imageString];

            NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:fullName];

            imagePickerCell.selectedImageName = imagePath;

            

            if (!imagePickerCell.selectedImageObject)

            {

                NSString *imageString = @"test";

                NSString *fullName = [NSString stringWithFormat:@"Documents/%@", imageString];

                NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:fullName];

                imagePickerCell.selectedImageName = imagePath;

            }

            

            

            //Configure Bound Cell Attributes

            

            cell.accessoryType = UITableViewCellAccessoryNone;

           

            

            return;

        }

        else {

            cell.height = 54;

            return;

        }

        

    };

 

from the code you can see I have a placeholderimageName  "test" assigned to the scimagepicker. Along with this, I created the image in the Documents folder and then created path to the "test" image.

 

However, when I launch the app and seque to the detail view, the scimagepicker cell content is nil. However, when I select scimagepicker and clear blank image, upon completion the default image is shown in the cell.

 

Any ideas, thoughts would be appreciated.

 

Thanks

 



#2 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 04 January 2014 - 04:32 PM

hi todd

 

i just did a quick look through the source code and saw that STV assigned to the file name the documents path itself.. and i see you are also assigning this full path

 

 

so what happens if you try

replace your code
NSString *imageString = @"test";
NSString *fullName = [NSString stringWithFormat:@"Documents/%@", imageString];
NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:fullName];
imagePickerCell.selectedImageName = imagePath;

with
imagePickerCell.selectedImageName = @test";

since STV assigns the doc path to the string of the file name you pass in


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


#3 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 04 January 2014 - 04:47 PM

Ozie,

 

thanks for the input--

 

imagePickerCell.selectedImageName = @test";--produces the same result.....still get blank image until SCimagePicker goes through select cycle.

 

TRG



#4 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 04 January 2014 - 04:53 PM

ok.. one more thing to test

add this right at the end of the function and let me know what happens

 

[cell layoutSubviews];


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


#5 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 04 January 2014 - 04:55 PM

and i just had another thought..

i think the code for loading the image should be moved into the cellAction for willDisplay, as willConfigure might not be called when recycling cells..

you want the code to run for when its displayed


Edited by ozie, 04 January 2014 - 04:56 PM.

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


#6 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 04 January 2014 - 07:19 PM

Ozie,

 

This code snippet, incorporating "willdisplay" works if you are adding a "new item"--ie the default image will show on the SCImagePicker:

 

myPropertyDef.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        
            if([cell isKindOfClass:[SCImagePickerCell class]])
            {
            SCImagePickerCell *imagePickerCell = (SCImagePickerCell *) cell;
            NSString *strPicked = imagePickerCell.selectedImageName;
        
            if (!imagePickerCell.selectedImageObject)
            {
                NSLog(@"IS NULL");
                imagePickerCell.placeholderImageName = @"test";
                imagePickerCell.placeholderImageTitle = @"";
                
                return;
            }

 

However, the "default image" will not show up in the scimagepicker if an item already exists...code still throws a blank image for SCImagePicker.

 

Also tried [cell layoutsubviews]--however that did not work either.

 

Thanks for the partial fix.

 

TRG



#7 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 06 January 2014 - 03:10 PM

Ozie,

 

as a follow-up to the above discussions. I have two apps--the "default image" for SCImagePicker works for one app as advertised, does not work for the other app. Has to be in my code somewhere or how I have it laid out.

 

Whats even more aggravating is in the app that the "image default" does work in, when you replace with actually photo and click on photo, a separate model controller does not launch with the image. However, this works in the other app.

 

ARGH







Also tagged with one or more of these keywords: data-stores, models, cells, actions

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users