cocoa touch - UISlider core data programing -
im working on simple "point based" app.
under settings user set´s number of points needed "goodie" using slider.
-(ibaction) sliderchanged: (id)sender { uislider *slider = (uislider *) sender; int progressasint =(int)(slider.value +0.5); nsstring *newtext = [[nsstring alloc] initwithformat:@"%d",progressasint]; sliderlabel.text = newtext; [newtext release];
this works fine, how store slider value in core data model, , how make slider show stored value when view loads.
hope u can me out :-d
hey gerry3 found error. never set tod-object in settingsviewcontroller, with:
nsfetchrequest *request = [[nsfetchrequest alloc] init]; [request setentity:[nsentitydescription entityforname:@"todo" inmanagedobjectcontext:_context]]; nserror *error = nil; nsarray *array = [_context executefetchrequest:request error:&error]; if (array == nil) { // deal error... } if(array.count > 0){ todo = [array objectatindex:0]; } else { // no 1 fetch - generate 1 todo = [nsentitydescription insertnewobjectforentityforname:@"todo" inmanagedobjectcontext:_context]; [todo retain];
your code works charm .....
thanks skov
the key here core data stores numeric attributes (e.g. integers, floats, etc) nsnumber objects.
say entity called record , has integer attribute called 'progress'.
if create managed object instance of record named 'record', can set progress this:
[record setvalue:[nsnumber numberwithinteger:progressasint] forkey:@"progress"];
when want update view value model (usually in viewwillappear:
), can progress this:
nsnumber *progressnumber = [record valueforkey:@"progress"]; slider.value = [progressnumber floatvalue];
alternatively, if generate class files record entity, can do:
record.progress = [nsnumber numberwithinteger:progressasint];
and:
slider.value = [record.progress floatvalue];
Comments
Post a Comment