Fetch Object with relationship with NSFetchedResultsController - objective-c

Here's my problem:
I've got 2 Entities :
Session (Date date, String name, NSSet behaviours)
Behaviour (String category, String Time, String name, NSManagedobject session).
They are in a one-to-many relationship.
In SessioneViewController, I fetch the Session and the Behaviours:
// This is for the fetch request
#property (nonatomic, ratain) NSArray *sessionArray;
// Here I create the Session Object
Session *newSession = [NSEntityDescription insertNewObjectForEntityForName:#"Session" inManagedObjectContext:self.managedObjectContext];
newSession.name = self.lblName.text;
newSession.date = [NSDate date];
self.managedObjectContext save:nil];
// I add the Session into the Array
self.sessionsArray = [self.sessionsArray arrayByAddingObject:newSession];
// Here I create the Behaviour Object:
Comportamento *newBehaviour = [NSEntityDescription insertNewObjectForEntityForName:#"Behaviour" inManagedObjectContext:self.managedObjectContext];
newBehaviour.name = cell.textLabel.text;
newBehaviour.category = #"Relationship";
newBehaviour.time = _lblTimer.text;
// Here I say which Session is part of the Behaviour
// --- EDIT ---
// Error Code: newBehaviour.session = [self.sessionsArray objectAtIndex:indexPath.row];
newBehaviour.session = [self.sessionsArray lastObject];
Then I have two view controller classes in which I want to display the Sessions and then when a Session is selected I want the related Behaviours.
// In "ArchiveSessionVC.h":
#property (nonatomic, strong) NSFetchedResultsController *frs;
// In "ArchiveSessionVC.m":
- (void) viwDidLoad
{
if(![[self frs] performFetch:&e]) {
NSLog(#"Error %#", e);
abort();
}
-(NSFetchedResultsController *)frs {
if (_frs != nil) {
return _frs;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Session" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"date"
ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
_frs = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
return _fetchedResultControllerSessions;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"SessioneCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Sessione *sessione = [self.fetchedResultControllerSessions objectAtIndexPath:indexPath];
cell.textLabel.text = sessione.nome;
return cell;
}
Here is where I push the Second view controller for display the Behaviuors:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Push del ViewController dei comportamenti:
ArchiveBehaviuorsVC *aBehavioursVC = [[ArchiveBehaviuorsVC alloc] initWithNibName:#"ArchiveBehaviuorsVC" bundle:nil];
aBehavioursVC.sessioneSelezionata = [self.fetchedResultControllerSessions objectAtIndexPath:indexPath];
[self.navigationController pushViewController:aBehavioursVC animated:YES];
}
My ArchiveBehaviuorsVC is like this:
//"ArchiveBehaviuorsVC.h"
#property (nonatomic, strong) Session *selectedSession;
-(NSFetchedResultsController *)fetchedResultControllerBehaviours
{
if (_fetchedResultControllerBehaviours != nil) {
return _fetchedResultControllerBehaviours;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Behaviour" inManagedObjectContext:self.managedObjectContext];
//NSPredicate *predicate = [NSPredicate predicateWithFormat:#"session == %#",self.sessioneSelezionata];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"nome"
ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
_fetchedResultControllerBehaviours = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
return _fetchedResultControllerBehaviours;
}
This is part of the code but it doesn't work. How do I tell the fetchedResultzController to display only the Behaviours associate with the Session?
-- EDIT ---
I found the problem, it wasn't a NSPredicate error, the problem was in this line of code:
// Error Code: newBehaviour.session = [self.sessionsArray objectAtIndex:indexPath.row];
// Right Code:
newBehaviour.session = [self.sessionsArray lastObject];

The predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"session == %#",self.sessioneSelezionata];
looks ok to me.
Are you sure you are obtaining the wrong behavior? Did you try to enable SQL debugging?
-com.apple.CoreData.SQLDebug X
where X can be 1,2 or 3. The higher the value the more SQL output.
In addition, when you do a save ALWAYS pass in an error reference.
NSError* error = nil;
[context save:&error];
The above snippet returns a bool value so check it. If NO is returned print the error.

Related

Incorrectly calculated sum expressionForKeyPath sum: core data

May be I'm doing something wrong?
So, I have few Entities with relationship
"Shop->amountIncome and -> amountExpense"
And I'm trying to count total income and expense.
I have dynamic tabelView
I start with
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
and some search
Shop *shop = nil;
if (self.searchPredicate == nil) {
shop = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
else {
shop = [self.fetchedResultsController.fetchedObjects filteredArrayUsingPredicate:self.
searchPredicate][indexPath.row];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = shop.shopName;
So I start with request of my entity "Shop" (it has relationship -> amountIncome and
->amountExpense
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Shop"
inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
I have several Shops, so I do predicate by shopName
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:#"shopName = %#", shop.shopName]];
fetchRequest.resultType = NSDictionaryResultType;
after all I do stuff for calculating sum:
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
expressionDescription.name = #"amountIncome";
expressionDescription.expression = [NSExpression expressionForKeyPath:#"#sum.incomes.amountIncome"];
expressionDescription.expressionResultType = NSDecimalAttributeType;
NSExpressionDescription *expressionDescriptionExpense = [[NSExpressionDescription alloc] init];
expressionDescriptionExpense.name = #"amountExpense";
expressionDescriptionExpense.expression = [NSExpression expressionForKeyPath:#"#sum.expenses.amountExpense"];
expressionDescriptionExpense.expressionResultType = NSDecimalAttributeType;
fetchRequest.propertiesToFetch = #[expressionDescription, expressionDescriptionExpense];
NSError *error = nil;
NSArray *result = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(#"%#",result);
if (result == nil)
{
NSLog(#"Error: %#", error);
}
else
{
NSNumber *sumOfAmounts = [[result objectAtIndex:0] objectForKey:#"amountIncome"];
NSNumber *sumOfAmountsExpense = [[result objectAtIndex:0] objectForKey:#"amountExpense"];
NSString* amount = [NSString stringWithFormat:#"inc %#/ exp %#/ difference",
sumOfAmounts, sumOfAmountsExpense];
and results I'd like to show in detailTextLabel
cell.detailTextLabel.text = amount;
}
return cell;
The thing is, that amountIncome counting correct, but amountExpense counting wrong (like double counting)
What I'm missing, what my mistake?
P.S. Sorry my English ;(
Have you tried KVC?
NSNumber *sumIncome = [allIncomes valueForKeyPath:#"#sum.amountIncome"];
NSNumber *sumExpense = [allExpenses valueForKeyPath:#"#sum.amountExpense"];

CoreData ascending:YES, show latest from the bottom

I have list of messages in my Core Data store(100 messages).
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"created" ascending:YES];
NSArray *sortDescriptors = #[sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchLimit:20];
It shows only first 20 messages in the order I need.
What I need to do is: Show last 20 messages, sorted by date of creation, but they should appeared form the bottom of the TableView.
Storage:
1 : Test 1
2 : Test 2
3 : Test 3
It shows now as :
1 : Test 1
2 : Test 2
**Supposed to show in table View:**
3 : Test 3
2 : Test 2
1 : Test 1
fetchedResultsController:
- (NSFetchedResultsController *)fetchedResultsController{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Messages" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setFetchLimit:20];
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"created" ascending:YES];
NSArray *sortDescriptors = #[sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"(owner = %#) and (stream == %#) and (topic == %#)", ownerGuid,openStream,currentTopic];
[fetchRequest setPredicate:predicate];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
self.fetchedResultsController.delegate = self;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
[self.fetchedResultsController performFetch:NULL];
return _fetchedResultsController;
}
All you should need to do is change the sortDescriptor to use ascending:NO so that it will get the last 20 messages.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"created" ascending:NO];
Now, you've got the right messages, they're just backwards in your array. You can easily reverse an array using the following code.
NSArray *messages = [[[fetchedMessages] reverseObjectEnumerator] allObjects];
EDIT:
Since you using a NSFetchedResultsController this solution would require a lot of additional code to work.
The easiest solution I can think of would be implement a custom method for getting your objects out of a fetched results controller.
- (id)objectAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger sectionCount = [self.tableView numberOfRowsInSection:indexPath.section];
NSInteger newRowIndex = sectionCount - indexPath.row - 1;
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:indexPath.section];
return [self.fetchedResultsController objectAtIndexPath:newIndexPath];
}
Then just replace
[self.fetchedResultsController objectAtIndexPath:indexPath];
with
[self objectAtIndexPath:indexPath];
#Clever answer is working for me. I called only NSIndexPath (return newIndexPath). I did not override method of the objectAtIndexPath. I was replaced below method.
- (NSIndexPath *)objectNewIndexPath:(NSIndexPath *)indexPath {
NSInteger sectionCount = [self.tableView numberOfRowsInSection:indexPath.section];
NSInteger newRowIndex = sectionCount - indexPath.row - 1;
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:indexPath.section];
return newIndexPath;
}
Then just replace
[self.fetchedResultsController objectAtIndexPath:[self objectNewIndexPath:indexPath];

Passing fetchedResultsController object to child returns nil later

I have a UITableView for my iPad app which when you tap on a row, will display a popOver with another table in it with one section. The popOver table section header is dependant on values from the fetchedResultsController on the main UITableView controller. When the popover first loads the information is correct. However, after the user taps on a cell in the popover, it goes to another view inside the popover that will allow you to edit data. Once you save, I call a delegate method to refresh the main UITableView while the popover stays shown. Then the view where the user edited the data is dismissed so it goes back to the popover UITableView. At this point the fetchedResultsController that was passed in as slot is now nil. I cannot figure out why it is doing this.
Why is the slot now nil in SlotViewController and how do I prevent it?
#interface
NSFetchedResultsController *fetchedResultsController;
Main UITableView
#synthesize fetchResultsController = _fetchedResultsController;
- (NSFetchedResultsController *)fetchedResultsController {
/*
Set up the fetched results controller.
*/
if (_fetchedResultsController != nil) {
NSLog(#"RETURNING FETCHEDRESULTS");
return _fetchedResultsController;
}
NSLog(#"Should only be called once");
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = nil;
if ([[dataObj.client objectForKey:#"appt_method"] integerValue] == 2) {
entity = [NSEntityDescription entityForName:#"Slots" inManagedObjectContext:[[CoreDataHelper sharedInstance] managedObjectContext]];
} else {
entity = [NSEntityDescription entityForName:#"Appointments" inManagedObjectContext:[[CoreDataHelper sharedInstance] managedObjectContext]];
}
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:nil];
//[fetchRequest setIncludesPendingChanges:YES];
// Set the batch size to a suitable number.
//[fetchRequest setFetchBatchSize:20];
// Sort using the date / then time property.
NSSortDescriptor *sortDescriptorDate = [[NSSortDescriptor alloc] initWithKey:#"date" ascending:YES];
NSSortDescriptor *sortDescriptorTime = [[NSSortDescriptor alloc] initWithKey:#"start_time" ascending:YES selector:#selector(localizedStandardCompare:)];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptorDate, sortDescriptorTime, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Use the sectionIdentifier property to group into sections.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[[CoreDataHelper sharedInstance] managedObjectContext] sectionNameKeyPath:#"date" cacheName:nil];
// aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Slots *selectedSlot = [_fetchedResultsController objectAtIndexPath:indexPath];
SlotViewController *slotView = [parentNav.storyboard instantiateViewControllerWithIdentifier:#"SlotViewController"];
[slotView setSlot:selectedSlot];
CGRect rect = [self rectForRowAtIndexPath:indexPath];
rect.size.width = rect.size.width / 3;
UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:slotView];
popOver = [[UIPopoverController alloc] initWithContentViewController:navBar];
popOver.delegate = self;
//[popOver setPopoverContentSize:CGSizeMake(320, 460) animated:YES];
[popOver presentPopoverFromRect:rect inView:self permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
SlotViewController / popover UITableView
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSLog(#"slot: %#", _slot.date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyyMMdd"];
NSDate *currDate = [dateFormatter dateFromString:_slot.date];
[dateFormatter setDateFormat:#"h:mma"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:#"GMT"]];
NSDate *midnight = [NSDate dateWithTimeIntervalSince1970:0];
NSDate *startTimeDate = [midnight dateByAddingTimeInterval:[_slot.start_time integerValue] * 60];
NSDate *endTimeDate = [midnight dateByAddingTimeInterval:[_slot.end_time integerValue] * 60];
NSString *startTime = [dateFormatter stringFromDate:startTimeDate];
NSString *endTime = [dateFormatter stringFromDate:endTimeDate];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:#"en_US_POSIX"];
[dateFormatter setDateFormat:#"E, MMM dd, yyyy"];
return [NSString stringWithFormat:#"%# %#-%#",[dateFormatter stringFromDate:currDate], startTime, endTime];
}
I'm able to get it working properly by changing the didSelectRowAtIndexPath code from
Slots *selectedSlot = [_fetchedResultsController objectAtIndexPath:indexPath];
to
Slots *selectedSlot = [Slots disconnectedEntity];
Slots *tmpSlot = [_fetchedResultsController objectAtIndexPath:indexPath];
for (id key in tmpSlot.entity.attributesByName) {
[selectedSlot setValue:[tmpSlot valueForKey:key] forKey:key];
}
disconnectedEntity
is a Core Data managed context that is not tied to an object.
+ (id)disconnectedEntity {
NSManagedObjectContext *context = [[CoreDataHelper sharedInstance] managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:#"Slots" inManagedObjectContext:context];
return [[self alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:nil];
}
However I am wondering why the original code will not work. I am assuming that it is because the fetchedResultsController is passing the reference to selectedSlots so when fetchedResultsController updates, the reference no longer exists?

NSFetchedResultsController for new object

I have UITableViewController with static editable cells. In my UITableViewController I make CoreData object, like this:
- (User*)user {
if (_user == nil) {
_user = [NSEntityDescription insertNewObjectForEntityForName:TABLE_USER inManagedObjectContext:self.managedObjectContext];
NSError* error;
[self.managedObjectContext save:&error];
if (error != nil) {
abort();
}
}
return _user;
}
I want to get the object in NSFetchedResultsController that would display its fields in a table, and then save the object.
I'm trying to do:
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:TABLE_USER_PROFILE inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"lastName" ascending:NO];
NSArray *sortDescriptors = #[sortDescriptor];
NSPredicate* pred = [NSPredicate predicateWithFormat:#"%# = %#", TABLE_USER, self.user];
[fetchRequest setPredicate:pred];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:TABLE_USER];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
abort();
}
return _fetchedResultsController;
}
But it didn't work. I get empty fetchedResultsController.
If self.user is a NSManagedObject and you query against a User entity you could try to edit your predicate like the following:
NSPredicate* pred = [NSPredicate predicateWithFormat:#"self == %#", self.user];
Hope that helps.
P.S. If my answer doesn't work try to provide some other details (see my comment)

Objective-C, iOS, Core Data, Table Cells empty

I've been trying to get through this for a couple of hours now and trying to figure out what is wrong with this code. I'm using core data to save title and a subtitle in a table cell.
I have some setups in my app delegate(sharedAppDelegate) and in my tableview is were I try to inset data into my cells.
Here is what I have in My appDelegate.m:
+(StaticTableAppDelegate *)sharedAppDelegate
{
return sharedInstance;
}
-(NSArray *)allConsoles
{
NSManagedObjectContext *moc = [[StaticTableAppDelegate sharedAppDelegate] managedObjectContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Homework" inManagedObjectContext:moc];
[fetch setEntity:entity];
//sort
NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey:#"title" ascending:YES];
NSArray *sortdescriptors = [NSArray arrayWithObject:sd];
[fetch setSortDescriptors:sortdescriptors];
NSError *error;
NSArray *result = [moc executeFetchRequest:fetch error:&error];
if(!result){
NSLog(#"%#", [error localizedDescription]);
return nil;
}
return result;
}
And in the view I have this(I imported app delegate):
- (void)viewDidLoad
{
[super viewDidLoad];
NSManagedObjectContext *cxt = [[StaticTableAppDelegate sharedAppDelegate] managedObjectContext];
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Homework" inManagedObjectContext:cxt];
[request setEntity:entity];
NSArray *arry = [cxt executeFetchRequest:request error:&error];
for( UserData *user in arry){
NSLog(#"title %#", user.title);
NSLog(#"details %#", user.details);
}
StaticTableAppDelegate *ad = [StaticTableAppDelegate sharedAppDelegate];
NSArray *list = [ad allConsoles];
if ([list count]==0) {
tabledata = [[NSMutableArray alloc] init];
tablesubtitles = [[NSMutableArray alloc]init];
[tabledata addObject:#"hello2"];
[tabledata addObject:#"hello2"];
[tabledata addObject:#"hello2"];
[tabledata addObject:#"hello2"];
[tablesubtitles addObject:#"details"];
[tablesubtitles addObject:#"details"];
[tablesubtitles addObject:#"details"];
[tablesubtitles addObject:#"details"];
NSManagedObjectContext *moc = [ad managedObjectContext];
for (int i=0; i<[tabledata count]; i++) {
NSManagedObject *newTabledata = [NSEntityDescription insertNewObjectForEntityForName:#"Homework" inManagedObjectContext:moc];
[newTabledata setValue:[NSString stringWithFormat:[tabledata objectAtIndex:i]] forKey:#"title"];
NSManagedObject *newTablesub = [NSEntityDescription insertNewObjectForEntityForName:#"Homework" inManagedObjectContext:moc];
[newTablesub setValue:[NSString stringWithFormat:[tablesubtitles objectAtIndex:i]] forKey:#"details"];
}
list = [ad allConsoles];
}
tabledata = [tabledata mutableCopy];
}
And tableview method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"homeworkcell"];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"homeworkcell"];
}
cell.textLabel.text=[[tabledata objectAtIndex:indexPath.row] valueForKey:#"title"];
cell.detailTextLabel.text = [[tablesubtitles objectAtIndex:indexPath.row] valueForKey:#"details"];
cell.textLabel.font = [UIFont systemFontOfSize:14.0];
cell.textLabel.backgroundColor = [ UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
//-----------------------------------------START----------------------------Set image of cell----
cellImage = [UIImage imageNamed:#"checkboxblank.png"];
cell.imageView.image = cellImage;
//--------------------------------------------END---------------------------end set image of cell--
return cell;
}
I appreciate the help.
This is how to store into coreData....If u can change it for your code..
MortgageAppAppDelegate *MortDataObj=(MortgageAppAppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [MortDataObj managedObjectContext];
loanDetails=[NSEntityDescription
insertNewObjectForEntityForName:#"LoanDetails"
inManagedObjectContext:context];
loanDetails.loanName = name;
loanDetails.loanDescription = desc;
NSError *error;
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}