[英]Storing each char from a text field in an array?
我無法將文本字段中的輸入存儲到一個數組中,其中每個字符都位於一個單獨的索引處。
我已經嘗試將輸入存儲為字符串,所以我可以將它全部大寫並刪除空格,但這也引起了我的問題。
我想,一旦它被存儲,我可以循環遍歷每個字母並將每個字符添加到一個可變數組。
感謝您提前提供的任何幫助。
如果您查看UITextFieldDelegate,您可以從此委托中找到許多可能對您的任務有用的好方法。
每個用戶在UITextField
按鍵時都會調用此委托中的方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
//assuming dict is declared NSDictionary
[dict setObject:[yourTextField.text stringByReplacingCharactersInRange:range withString:string] forKey:@"KEY"];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *string = textField.text;
NSMutableArray *theArray = [NSMutableArray array];
for (int i = 0; i < [string length]; i++)
{
[theArray addObject:[NSString stringWithFormat:@"%c",[string characterAtIndex:i]]];
}
}
一旦用戶結束他/她的編輯,我會進行存儲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.