Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:02:52+00:00 2026-06-10T21:02:52+00:00

I am trying an app with a tableview which has profile name and images

  • 0

I am trying an app with a tableview which has profile name and images of people..the tableview is editable and adding new name and picture, deleting an existing one and rearranging the table are possible..the tableview and changes to it should be saved using core data..I have almost completed it but core data part is having some problems..

I have implemented core data to provide data persistence for the tablecells..everytime i restart the app, the table cell keeps the changes that were last made..but the cell image doesn’t load..how to make that image persist?

NSManagedObject *person1 = [NSEntityDescription
                            insertNewObjectForEntityForName:@"Person"
                            inManagedObjectContext:context];
NSManagedObject *person2 = [NSEntityDescription
                            insertNewObjectForEntityForName:@"Person"
                            inManagedObjectContext:context];

[person1 setValue:@"Bruce" forKey:@"personName"];
UIImage *image1 = [UIImage imageNamed:@"image1.jpg"]; 
NSData *imageData1 = UIImageJPEGRepresentation(image1, 0.9);
[person1 setValue:imageData1 forKey:@"personPicture"];
NSLog(@"Image1 data %@",imageData1);

[person2 setValue:@"Alfred" forKey:@"personName"];
UIImage *image2 = [UIImage imageNamed:@"image2.jpg"]; 
NSData *imageData2 = UIImageJPEGRepresentation(image2, 0.9);
[person2 setValue:imageData2 forKey:@"personPicture"];

NSError *error;
if (![context save:&error]) {
        NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}

then fetch was done as

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"Person" inManagedObjectContext:context];

[fetchRequest setEntity:entity];
NSError *error1 = nil;
self.persons = [[context executeFetchRequest:fetchRequest error:&error1] mutableCopy];

this much was done in didFinishLaunchingWithOptions in appDelegate. The data was then used in the cellForRowAtIndexPath method in the tableview class implementation file as

Person *thisPerson = [persons objectAtIndex:indexPath.row];
cell.textLabel.text = thisPerson.personName;

UIImage *image = [UIImage imageWithData:[thisPerson valueForKey:@"personPicture"]];
if ( image == nil ) {
    image = [UIImage imageNamed:@"QuestionMark.jpg"]; 
}
cell.imageView.image = image;

The cell is loading properly..and all the editing part I did is also being saved and reloaded..the images load properly when loading the app for the 1st time..when it is restarted the QuestionMark.jpg image appears..which is because the image is nil..I tried NSLog to display the 1st image data and got this:

2012-09-07 17:05:59.395 Sample Project[1688:fb03] Image1 data <ffd8ffe0 00104a46     
49460001 01000001 00010000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 
00000001 00010000 87690004 00000001 00000026 00000000 0003a001 00030000 00010001 
0000a002 00040000 00010000 00bea003 00040000 00010000 01090000 .........
......               .............. 7ff4d668 0356803f 357e307f c94ff14f fd858ffe 
9af4ba00 f39a00cf a00d0a00 cfa00280 0a002803 ffd9>

a lot more was there where i added the dots..anyway..this seems to show that its saving the data..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:02:54+00:00Added an answer on June 10, 2026 at 9:02 pm

    If the image is relatively small, then save it as a NSData object in the core data repository. I do this for thumbnails etc. For huge images, you can save a URL and put the image in your Documents folder, and save a URL to the file (NSURL) as an object in Core Data too. If you delete that core data entity, it has to then delete the file.

    EDIT: Regarding the “Sorry…” comment in your Question, change this line:

    UIImage *image = [UIImage imageWithData:[thisPerson valueForKey:@"personPicture"]];
    

    to

    NSData *data = thisPerson.personPicture;
    if(data) {
      NSLog(@"Image class: %@", NSStringFromClass[data class]);
      if([data isKindOfClass:[NSData data]]) {
        NSLog(@"Data was of size %u", [data length]);
        UIImage *image = [UIImage imageWithData:data];
        if(image) NSLOg(@"SUCCESS!");
        else NSLog(@"PROBLEM: cannot create image from data");
      }
    } else {
      NSLog(@"BIG PROBEM - personPicture is nil");
    }
    

    You will learn much from the output here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Xcode and I'm trying to create an app which has a
I'm making a 'post text' app and trying to update my database with name
I'm working on a iPhone app which has a pretty large UITableView with data
I am trying to create a contacts like app for iphone where the name
I have a MonoTouch iPhone app which has a UITableViewController as it's main view
In my app, I have a UITableView which has some custom cells and in
I am trying to learn how to use tables, I have my app which
I'm new to android and android development. I'm trying to make an app similar
I'm trying to make a Core Data app in which when you select one
I'm trying to implement a UI structured like in the Tweetie app, which behaves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.