0

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?

2
  • can you give an example of the text that will be in the field and the output you want? Commented Apr 8, 2011 at 8:26
  • Don't use +stringWithFormat: when you don't need to. Parsing a format string is expensive. Just use [[[textfield text] copy] autorelease] Commented Apr 8, 2011 at 10:28

4 Answers 4

4

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];
Sign up to request clarification or add additional context in comments.

2 Comments

Even if there is no need to create a new NSString, could you tell us why his code does not work ?
Yes, %s is expecting a cstring not NSString. If you want to use a NSString in a formet use %@
1

Try:

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

Comments

1

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

Comments

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

    NSlog(@"%@",pole);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.