[英]UITableView and NSMutableArray dynamic?
I have a tableview where the user can add a cell (with textfield in it) by pressing an add button. 我有一个tableview,用户可以通过按添加按钮来添加单元格(其中带有文本字段)。
I write the text (from textfield) to NSMutable array, and save in NSUserdefaults. 我将文本(来自文本字段)写入NSMutable数组,并保存在NSUserdefaults中。 works fine!
工作正常!
But when the user selects (for example) row 5, I switch to a new view with some textfields in it. 但是,当用户选择(例如)第5行时,我切换到其中包含一些文本字段的新视图。
How can I add the values (text) from the textfields in a new array and store it in the userdefaults? 如何将文本字段中的值(文本)添加到新数组中并将其存储在userdefaults中? Should I create an array for each row the user has selected?
我应该为用户选择的每一行创建一个数组吗? (indexpath.row) I need the values to show in another view.
(indexpath.row)我需要这些值才能在另一个视图中显示。
You can use a NSMutableDictionary. 您可以使用NSMutableDictionary。 It would look like:
它看起来像:
{
"rowOne":{"textFieldOne":"DataOne", "textFieldTwo":"DataTwo"},
"rowTwo":{"textFieldOne":"DataOne", "textFieldTwo":"DataTwo"}
}
To get out your Array of the tableViewCells like you were before you would use: tableArray = [dictFromUserDefaults allKeys]; 要像使用之前一样取出tableViewCells的数组,请执行以下操作:tableArray = [dictFromUserDefaults allKeys];
When you need to get the data for the fields with in that row you use 当您需要获取该行中的字段的数据时,可以使用
dataDictionary = [dictFromUserDefaults objectForKey:[tableArray objectAtIndex:index.row]];
And for each textField you would use: 对于每个textField,您将使用:
textfieldOne.text = [dataDictionary objectForKey:@"textFieldOne"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.