【发布时间】:2012-11-28 19:47:04
【问题描述】:
我有一个在 iOS 6 中使用 UIKit 状态保存的应用程序。我能够保存/恢复视图控制器的状态,即选择了哪个选项卡和导航控制器层次结构,但是我无法恢复我的表视图它是抵消的。我的故事板中有一个用于视图以及视图控制器的恢复标识符,并且视图控制器(表的数据源)实现UIDataSourceModelAssociation,如下所示:
- (NSString *)modelIdentifierForElementAtIndexPath:(NSIndexPath *)indexPath inView:(UIView *)view
{
TSStatus *status = [self._fetchedResultsController objectAtIndexPath:indexPath];
return status.objectID.URIRepresentation.absoluteString;
}
- (NSIndexPath *)indexPathForElementWithModelIdentifier:(NSString *)identifier inView:(UIView *)view
{
NSURL *statusURL = [NSURL URLWithString:identifier];
NSManagedObjectID *statusID = [[TSDataController sharedController].persistentStoreCoordinator managedObjectIDForURIRepresentation:statusURL];
TSStatus *status = (TSStatus *)[[TSDataController sharedController].mainContext objectWithID:statusID];
return [__fetchedResultsController indexPathForObject:status];
}
当应用程序进入后台时会调用modelIdentifierForElementAtIndexPath:inView:,但不会调用modelIdentifierForElementAtIndexPath:inView:。
【问题讨论】:
-
我认为您的最后一段是错字? --- “modelIdentifierForElementAtIndexPath:inView: 在应用程序进入后台时被调用,但是 modelIdentifierForElementAtIndexPath:inView: 永远不会被调用。”
标签: iphone ios ios6 uikit uikit-state-preservation