[英]Why is the CAGradientLayer removed from view after modal view controller is dismissed
[英]stop view controller from reloading after another view controller is dismissed
我有2個ViewController: ControllerA
和ControllerB
在ControllerA
上,用戶可能已經填寫了許多tableViews和輸入框。 用戶可以從ControllerA
單擊按鈕以啟動ControllerB
如下所示:(我未使用NavigationController)
UIStoryboard *storyBorad = [UIStoryboard storyboardWithName: @"Main_iphone" bundle:nil];
UIViewController *secondController = [Storyboard instantiateViewControllerWithIdentifier:@"ControllerB"];
[self presentViewController: secondController animated: YES completion: nil];
在ControllerB
,用戶可以單擊關閉按鈕,並顯示以下代碼:
[self dismissViewControllerAnimated:YES completion:nil];
用戶返回到以前的ControllerA
但是我看到ControllerA
重新加載了所有數據,並且文本框中的所有內容均為空。
我讀過很多類似的案例,但不了解如何解決這個問題。
我發現的選擇:
ControllerB
之前,將數據保存在某個地方,然后在返回ControllerA
檢查並保存已保存的數據。 我該怎么做呢?? (似乎很乏味)。 ControllerA
不會從內存中刪除,並且當用戶從ControllerB
返回時在那里。 我希望這樣做可以使事情保持簡單(我知道記憶的演講)。 有什么幫助嗎?
如果要保留字段中的數據,則需要推送而不是模態顯示VC。
創建一個導航控制器並使用VC進行初始化,然后像下面這樣顯示VC:
UIStoryboard *storyBorad = [UIStoryboard storyboardWithName: @"Main_iphone" bundle:nil];
UIViewController *secondController = [Storyboard instantiateViewControllerWithIdentifier:@"ControllerB"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[navController pushViewController:secondController animated:YES];
在這種情況下,當您單擊“后退”按鈕時,您將被帶回到以前的VC,並且不會丟失任何數據!
如果您不希望有后退按鈕,則可以隱藏導航欄,而如果要關閉secondController
,則可以簡單地調用:
[self.navigationController popViewControllerAnimated:YES];
還要確保當您離開VC時,不要清除字段中的所有數據!!!! (確保數據是否為零,請檢查viewDidDisappear/viewWillDisappear
)
視圖是錯誤的位置,無法存儲您關心的數據。 發生的情況是,控制器B的視圖正在顯示,而控制器A的視圖正在卸載。 如果要確保保留用戶更改,則必須自己進行。
一種簡單的技術是擁有一個NSMutableDictionary,用於保存數據。 在出現B之前,先填充字典,然后在viewWillAppear中從字典中填充視圖。 如果從未出現B,則沒有任何可恢復的內容,並且字典將為空。 這意味着您無需測試是否要還原; 您可以無條件輸入該代碼路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.