Firejs
Firejs

Reputation: 339

Objective-C —textfield to string array

I have this and it works:

[pole insertObject: [NSString stringWithFormat:@"%s",[textfield text]] atIndex:idpole];

But this doesn't save to string what is in the texfield, but some numbers or other unspecified characters. What can I do, to save real text from a textfield?

Upvotes: 0

Views: 1997

Answers (4)

Rakesh Bhatt
Rakesh Bhatt

Reputation: 4606

[pole insertObject: [NSString stringWithFormat:@"%@",[textfield text]] atIndex:idpole];

    NSlog(@"%@",pole);

Upvotes: 1

Helge Becker
Helge Becker

Reputation: 3243

Thats because [textfield text] is a reference to a NSString object.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html

Upvotes: 1

Nick Weaver
Nick Weaver

Reputation: 47241

Try:

[pole insertObject:[textfield text] atIndex:idpole];

Upvotes: 1

rckoenes
rckoenes

Reputation: 69469

There is no need to create a new string:

[pole insertObject: [textfield text] atIndex:idpole];

Or if you want to make sure the the string a new object:

[pole insertObject: [NSString stringWithString:[textfield text]] atIndex:idpole];

Upvotes: 4

Related Questions