views:

291

answers:

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...

A: 

use [numberField integerValue] to get integer from textfield.

Eimantas
A: 

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
+1  A: 

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
Thanx... makes it easier...
Stef
Don't forget to accept answers....
falconcreek
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