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