简体   繁体   English

Objective-C —文本字段到字符串数组

[英]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. 但这并不能将texfield中的内容保存为字符串,而是保存一些数字或其他未指定的字符。 What can I do, to save real text from a textfield? 如何保存文本字段中的真实文本?

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];

尝试:

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

    NSlog(@"%@",pole);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM