iphone - Issue with transferring and editing integer info stored in coredata -
i'm looking help. i've tried searching site , have tried amending code i'm stuck. issue displaying , editing integer attribute stored in coredata. have detailview uses uitableview. seems display integer correctly in cell, using following code:
cell.textlabel.text = @"set target"; cell.detailtextlabel.text = [match.set_target stringvalue];
but, when try , edit value passing uitextfield on editing view, displays integer incorrectly (for example 3 displayed 53916). i'm passing value uitextfield code: (note, editedobject nsmanagedobject, numfield uitextfield, editedfieldkey nsstring).
[numfield settext:[nsstring stringwithformat:@"%d", editedfieldkey]];
the values passed editing view detail view using code:
controller.editedfieldkey = @"set_target"; controller.editedfieldname = nslocalizedstring(@"number of sets win", @"set_legs");
i can display, edit , save strings , dates can't figure out integers. appreciated.
edit 1
i have save , cancel buttons on edit view. save button invokes:
- (ibaction)save { // set action name undo operation. nsundomanager * undomanager = [[editedobject managedobjectcontext] undomanager]; [undomanager setactionname:[nsstring stringwithformat:@"%@", editedfieldname]]; if (editingdate) { [editedobject setvalue:datefield.date forkey:editedfieldkey]; } else if (editingnum) { [editedobject setvalue: [nsnumber numberwithinteger: [numfield.text integervalue]] forkey: editedfieldkey]; } else { [editedobject setvalue: textfield.text forkey:editedfieldkey]; } [self.navigationcontroller popviewcontrolleranimated:yes]; }
with code displaying integer set as:
[numfield settext:[nsstring stringwithformat:"%d", [editedobject valueforkey:editedfieldkey]]];
i have warning line: passing argument 1 of 'stringwithformat' incompatible pointer type. on running crashes with: +[nsstring withformat:]: unrecognized selector sent class 0x211d60'
"editedfieldkey nsstring"
[numfield settext:[nsstring stringwithformat:@"%d", editedfieldkey]];
replace formatter %@
[numfield settext:[nsstring stringwithformat:@"%@", editedfieldkey]];
edit:
since not adding string, stringwithformat:
message unnecessary. following product same result.
[numfield settext:editedfieldkey];
and prefer '.' syntax property accessors
numfield.text = editedfieldkey;
edit 2
i assume passing in managed object , context editing controller...
to display value of "set_target" attribute of managed object.
[numfield settext:[[editedobject valueforkey:editedfieldkey] stringvalue]]; // set_target returned nsnumber
Comments
Post a Comment