0
我用故事板佈局的建議應用程序接口,以節省搜索數據後SEGUE回報。我有一個按鈕,放在一個帶有頂部搜索欄控制器的表格視圖控制器中。我下面的蘋果如何做搜索非常基本的一個例子中here。此示例使用單個表視圖控制器並保存要在後續視圖中檢索的搜索項數據。搜索數據使用此代碼(我還包括對象定義)保存:iPhone應用程序崩潰時試圖
@interface SearchTableViewController : UITableViewController {
NSMutableArray *listOfLists;
NSMutableArray *filteredListOfLists;
NSString *savedSearchTerm;
NSInteger savedScopeButtonIndex;
BOOL searchWasActive;
}
@property (nonatomic, strong) NSMutableArray *listOfLists;
@property (nonatomic, strong) NSMutableArray *filteredListOfLists;
@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic) NSInteger savedScopeButtonIndex;
@property (nonatomic) BOOL searchWasActive;
@end
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
// save the state of the search UI so that it can be restored if the view is re-created
self.searchWasActive = [self.searchDisplayController isActive];
self.savedSearchTerm = [self.searchDisplayController.searchBar text];
self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
}
如果我註釋掉保存數據的三條芯線,一切正常,因爲它應該(有記憶的例外搜索對象的狀態)。我認爲正在發生的是,鑑於越來越被「破壞」的賽格瑞(被稱爲viewDidDisappear方法可能之前)的一部分,所以「自我」不再可用。
什麼是解決這一問題的正確/最佳方法是什麼?
感謝您的建議,我認爲做這樣的事情最終可以/和/或使用我一直在探索的AppDelegate作爲選項。 – user1159106
我剛纔發現,如果我把代碼放在table view controller的prepareForSegue方法中,它就可以工作。我猜測對於某些事情,prepareForSegue需要用來代替viewDidDisappear方法。 – user1159106
您仍然可以接受此答案... – Mundi