Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-27-2011, 08:47 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default Odd Method behaviour

Hey guys, i have a small problem with a method and how it affects my core data.

The line in question is this:
Code:
// set status to 1 here: 1 = complete and READY to sync
[self.referringObject setValue:[NSNumber numberWithInt:1] forKey:@"status"];
So this sets a value of 1 to the current object held in "self.referringObject". but i dont have this directly in a button or method. It is set in a void method that is designed to post data to a server.

In order to call this at the time of my (or the users) choosing i have it called from a button:
Code:
- (IBAction) test: (id) sender {
   
    [self createInvoiceItemsString];
}
But after pressing the button, if i use an SQLite browser to look up my database i can see that "status" hasnt been changed from 0 to 1.
Here is the twist though: If i call the exact same method from my viewDidLoad (in the same class) then it will alter it to be a 1 and everything will be set ok.

I dont mind that much if i have to set this in viewDidLoad, but it would potentially cause some problems with data management and as such it would be much better suited if the button was to set this. I have tried moving that line of code to the button so that sets it directly but this also doesnt change anything.

Any idea as to why this would work from viewDidLoad but not from a button?

Thanks in advance Joe
Meredi86 is offline   Reply With Quote
Old 05-27-2011, 09:23 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

I don't understand how is related that code to SQLite.....

however are you sure that all the code is running? use some NSLog...
__________________
dany_dev is offline   Reply With Quote
Old 05-27-2011, 10:05 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

Its related to SQLite because i am saving to core data - an SQLite database. So an SQLite browser such as "SQLite Database Browser" allows me to look at what has and hasnt been saved. An easy and effective way to check up on your database. The actual code itself has nothing to do with the SQLite language apart from it being the line of code that sets a value to my entity in core data.

Yes i am 100% sure that the line is being run, i have checked with both breakpoints and NSLogs. In both instances (call from viewDidLoad and from the IBAction) the line is executed. But if its from the button it just doesnt do anything
Meredi86 is offline   Reply With Quote
Old 05-27-2011, 11:02 AM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Meredi86 View Post
Hey guys, i have a small problem with a method and how it affects my core data.

The line in question is this:
Code:
// set status to 1 here: 1 = complete and READY to sync
[self.referringObject setValue:[NSNumber numberWithInt:1] forKey:@"status"];
So this sets a value of 1 to the current object held in "self.referringObject". but i dont have this directly in a button or method. It is set in a void method that is designed to post data to a server.

In order to call this at the time of my (or the users) choosing i have it called from a button:
Code:
- (IBAction) test: (id) sender {
   
    [self createInvoiceItemsString];
}
But after pressing the button, if i use an SQLite browser to look up my database i can see that "status" hasnt been changed from 0 to 1.
Here is the twist though: If i call the exact same method from my viewDidLoad (in the same class) then it will alter it to be a 1 and everything will be set ok.

I dont mind that much if i have to set this in viewDidLoad, but it would potentially cause some problems with data management and as such it would be much better suited if the button was to set this. I have tried moving that line of code to the button so that sets it directly but this also doesnt change anything.

Any idea as to why this would work from viewDidLoad but not from a button?

Thanks in advance Joe
Try adding a call to your managed object context's save method. That should force Core Data to commit unsaved changes to the "persistent store" (in your case, your SQL database.)
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 05-27-2011, 11:12 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

Duncan: Thanks, i couldnt put the line into the save method. that was happening at a different point much earlier in the code, and to add it there would have again messed up the data integrity.

However i found this hiding at the bottom of my viewDidLoad:
Code:
NSError *errorOne;
    [self.managedObjectContext save:&errorOne];
So i moved that out of the viewDidLoad and dropped it right under that one line (the only line that makes a change at this point so the only line that needs the save) And now it works - sweet. Usually something tiny that i have missed with these things!

If you dont save you dont get :P

Thanks again Duncan, much appreciated
Meredi86 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 341
6 members and 335 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0