我有一个在 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:
被调用,但从未被调用。