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

  • SEARCH
  • Home
  • 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 7855675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:27:16+00:00 2026-06-02T20:27:16+00:00

I am using coredata in my application to store data.i have to add the

  • 0

I am using coredata in my application to store data.i have to add the data in one view controller and retrieve it in another view controller.i tried the following code but it is not working.

//addViewController.m

-(IBAction)save:(id)sender
{

   CoreDataOneAppDelegate  *appDelegate = [[UIApplication sharedApplication] delegate];
   NSManagedObjectContext *context = [appDelegate managedObjectContext];
   NSManagedObject *newContact;
   newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Employee"
              inManagedObjectContext:context];
   [newContact setValue:name.text forKey:@"name"];
   [newContact setValue:amount.text forKey:@"amount"];
   name.text = @"";
   amount.text = @"";
//label
  status.text = @"saved";
  NSError *error;
  [context save:&error];
}

I want to retrieve the values and display them in a tableView

//retrieveViewController.m

 - (void)viewDidLoad
{
    objects = [[NSArray alloc]init];
    CoreDataOneAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Employee" 
            inManagedObjectContext:context];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
   [request setEntity:entityDesc];
    NSError *error;
    objects = [context executeFetchRequest:request 
                                 error:&error];
   [request release];
   [super viewDidLoad];
}

//tableView

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return  [objects count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
labelOne = [[UILabel alloc]initWithFrame:CGRectMake(5, 11, 110, 21)];
labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(230, 11, 70, 21)];


static NSString *cellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier]autorelease];
}

[cell.contentView addSubview:labelTwo];
[cell.contentView addSubview:labelOne];

 NSManagedObject *matches = nil;
 matches = [objects objectAtIndex:indexPath.row];
    NSString *str1=[NSString stringWithFormat:@"%@",[matches valueForKey:@"name"]];        
    labelOne.text = str1;
    NSString *str2=[NSString stringWithFormat:@"%@",[matches valueForKey:@"amount"]];        
    labelTwo.text = str2;

return cell;
}

I am getting EXC_BAD_ACCESS error.i tried using NSZombieEnabled and i got the following error.

2012-04-27 11:59:18.153 CoreDataOne[4370:207] *** -[_PFArray objectAtIndex:]: message sent to deallocated instance 0x5931e40

i am able to retrieve the values if write the code what i have written in viewDidLoad in cellForRowAtIndexPath but how to declare the numberOfRows.

  • 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-02T20:27:19+00:00Added an answer on June 2, 2026 at 8:27 pm

    It looks like you are not using ARC. I think you need to retain the result of your fetch request in viewDidLoad (don’t forget to release it in dealloc). Also, you are leaking by alloc/initing an array and then overwriting it.

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

Sidebar

Related Questions

I have developed a application that using core data framework to store the data.
I'm using CoreData (with SQLite as the store) in an iOS 4 iPhone application
I have a core data application that uses an NSPredicate in one of its
I am building an application using CoreData which will require me to store an
I have an existing large app using plists to store its data. I store
I have a navigation based application using Core Data and several levels of drill-down
I've a document-based application powered by Core Data with an in-memory store. I have
I'm using core data on an iPhone application. I have multiple persisntent stores that
I have an existing application using Core Data on the iPhone. Occasionally there would
my iPhone application should store some data persistantly by using Core Data functionality. Here

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.