我有兩個視圖。主視圖是ViewController,下一個是AddItemViewController。 ViewController有一個tableview,列出了你在添加AddItemViewController時添加的項目。 AddItemViewController上有一個按鈕,可以繼續使用ViewController。問題是,在返回ViewController期望添加一個項目時,ViewController的私有數據突然被設置爲nil。從賽格返回後,我丟失了數據和任何與我的對象交互的機會。ViewController的私有數據集在從segue返回後設爲零
這裏是是越來越設爲零
@property (strong, nonatomic) costEstimator *myCost;
@property NSString *testString;
我在做什麼錯誤的數據?
這裏是在AddItemViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
ViewController *vC = [segue destinationViewController];
[vC addSomething:_selectedItem withQuantity:[_quantBox.text doubleValue]];
}
任何幫助,非常感謝我的prepareforsegue代碼。謝謝:)
Segues(unwinds除外)總是實例化新的控制器!所以,如果你沒有放鬆,你不會「回頭」,你正在創建一個ViewController的新實例, – rdelmar
謝謝!那麼在大多數應用中常見的做法是什麼?人們不會使用賽格嗎?爲什麼沒有在iOS的基礎教程的前幾章中介紹過,比如segues? –
我不知道編寫教程的人爲什麼寫他們做的事。放鬆是一種延續,它只是一種不同的類型,所以你可以使用它,或者通過彈出(如果你推動)或解散(如果你已經提交)來回到代碼中。在進行任何iOS編程之前,您應該閱讀Apple的文檔。我將從「iOS視圖控制器編程指南」開始。它解釋了很多重要的概念。 – rdelmar