![](/img/trans.png)
[英]How to merge 2 NSDictionaries in NSMutableArray having same value in iOS?
[英]how to store old value and new value in same Nsmutablearray in ios
嗨,我是iOS
開發人員的新手。
我有UITableView
和UITextField
。 與在下一個屏幕中顯示此數組相比,我在textfield中設置了一些不同的值,並且在NSmutablearray
設置了每個textfield的值存儲。 顯示的數組值是完美的。 但是我的問題是當我切換回UITableView
屏幕並再次在UITextField
設置新值並將這些UITextField
值存儲在NSmutablearray
問題是新值被覆蓋為舊值。 但我想兩個值都存儲在NSArray
。
這是我的屏幕截圖
summaryvc顯示完美的數據。但是當我返回到屏幕並選擇其他項目而不是單擊placeorder。但是問題是我們無法在摘要屏幕中獲得舊的選定項目。
這是用於將數組存儲在Nsuserdefault中的按鈕操作代碼。 global.filteredArray是我的nsmutablearray.dic值是我的字典。
這是我的數組值
{
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];
}
請幫忙!
您必須在類而不是方法上聲明數組,這樣就可以了。
您可以執行以下操作:
-(void)viewDidLoad{
array = [[NSMutableArray alloc] init];
}
要么
使用NSUserDefaults
,它將一直保留到刪除該應用程序為止。
如果您有兩個屏幕,則要在此處編輯陣列,只需將數組引用傳遞到第二個屏幕。
FirstViewController:
設置陣列:
SecondViewController *svc= [[SecondViewController alloc] initWithNibName:@"secondviewcontroller" bundle:nil];
svc.firstViewArray=secondViewArray;
SecondViewController:
@property(nonatomic,retain)NSMutableArray *secondViewArray;
我可以看到您正在使用全局數組將數據存儲到NSUserDefaults。 在執行此操作時,您需要確保注意以下幾點:
希望對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.