[英]how to store old value and new value in same Nsmutablearray in ios
hi i am new in iOS
developer. 嗨,我是
iOS
开发人员的新手。
i have UITableView
and UITextField
. 我有
UITableView
和UITextField
。 I set some different value in textfield and each textfield's value store in NSmutablearray
than i display this array in next screen. 与在下一个屏幕中显示此数组相比,我在textfield中设置了一些不同的值,并且在
NSmutablearray
设置了每个textfield的值存储。 Displayed array value is perfect. 显示的数组值是完美的。 But my problem is when i switch back to the
UITableView
screen and than again set new value in UITextField
and these UITextField
value store in NSmutablearray
.but problem is new value is override to old value. 但是我的问题是当我切换回
UITableView
屏幕并再次在UITextField
设置新值并将这些UITextField
值存储在NSmutablearray
问题是新值被覆盖为旧值。 but i want both value store in NSArray
. 但我想两个值都存储在
NSArray
。
here my screen shot 这是我的屏幕截图
summaryvc display perfect data.but when i back to the screen and select other item than click the placeorder.but problem is we cant get old selected item in summary screen. summaryvc显示完美的数据。但是当我返回到屏幕并选择其他项目而不是单击placeorder。但是问题是我们无法在摘要屏幕中获得旧的选定项目。
here is button action code to store the array in Nsuserdefault. 这是用于将数组存储在Nsuserdefault中的按钮操作代码。 global.filteredArray is my nsmutablearray.dic value is my dictionary.
global.filteredArray是我的nsmutablearray.dic值是我的字典。
this is my array value 这是我的数组值
{
counts = 1;
"m_drycleaning_price" = 12;
"m_id" = 3;
"m_imagename" = d;
"m_iron_price" = 16;
"m_name" = "Coat(Man)";
"m_wash_price" = 14;
"m_washiron_price" = 13;
total = 12;
}
AppDelegate *myAppDelegate = [[UIApplication sharedApplication] delegate];
[myAppDelegate.arrayCounts addObject:dictValues];
myAppDelegate.arrayCounts[indexPath.row][@"counts"] = [NSString stringWithFormat:@"%d",(int)value];
myAppDelegate.arrayCounts[indexPath.row][@"total"] = [NSString stringWithFormat:@"%d",(int)y];
- (IBAction)placeorder:(id)sender
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:global.filteredArray forKey:@"def_orderarraylist"];
NSMutableArray *qualifiersArray = [NSMutableArray arrayWithArray:[userDefaults objectForKey:@"def_orderarraylist"]];
NSLog(@"qualifier array=%@",qualifiersArray);
[userDefaults synchronize];
}
please help! 请帮忙!
You must declare your array on class rather than on your method and you'll be fine. 您必须在类而不是方法上声明数组,这样就可以了。
You could do something like: 您可以执行以下操作:
-(void)viewDidLoad{
array = [[NSMutableArray alloc] init];
}
OR 要么
Use a NSUserDefaults
and it will stay until the app is deleted. 使用
NSUserDefaults
,它将一直保留到删除该应用程序为止。
If you have two screens you could simply pass the array reference to your second screen if you want to edit your array from there. 如果您有两个屏幕,则要在此处编辑阵列,只需将数组引用传递到第二个屏幕。
FirstViewController: FirstViewController:
Setup your array: 设置阵列:
SecondViewController *svc= [[SecondViewController alloc] initWithNibName:@"secondviewcontroller" bundle:nil];
svc.firstViewArray=secondViewArray;
SecondViewController: SecondViewController:
@property(nonatomic,retain)NSMutableArray *secondViewArray;
I can see you are using global array to store data to NSUserDefaults. 我可以看到您正在使用全局数组将数据存储到NSUserDefaults。 While doing this you need to make sure this points:
在执行此操作时,您需要确保注意以下几点:
Hope it will help you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.