3

I can set text in my managed object like this...

[editedObject setValue:textField.text forKey:editedFieldKey];

but I can't set this...

[editedObject setValue:numberField.text forKey:editedFieldKey];

In the XCode Template I can set this straight into the Managed Object but like this...

setValue:[NSNumber numberWithInt:200] forKey:@"jCode"];

but I can't seem to set it via a UITextField... Please can someone point me in the right direction... It will be highly appriciated...

Eimantas
  • 48,927
  • 17
  • 132
  • 168
Stef
  • 77
  • 2
  • 11

3 Answers3

9

You likely don't want to create an instance variable in the header. You can simplify your implementation and provide an (id)value all in one line.

[editedObject setValue:[NSNumber numberWithInteger:[[numberField text] integerValue]] forKey:editedFieldKey];
falconcreek
  • 4,170
  • 1
  • 21
  • 22
  • Thanks very much, this helped me and seemed to help @Stef. Not sure why he didn't accept this as the right answer though. :/ – Joshua Aug 06 '10 at 07:24
1

Thanx Eminatas...

1st what I did is in my header file add an int..

int userNumber;

Then in my implimentation, added this

NSString *numberString = [numberField text];
userNumber = [numberString intValue];

Then edited up managedObject like this...

[editedObject setValue:[NSNumber numberWithInt:userNumber] forKey:editedFieldKey];

Thanx for pointing me in the right direction...

Stef :-)

Stef
  • 77
  • 2
  • 11
0

use [numberField integerValue] to get integer from textfield.

Eimantas
  • 48,927
  • 17
  • 132
  • 168