[英]Saving reordering cells in UITableViewController with Core Data
[英]Animate row addition to UITableViewController with Core Data
我正在使用Master Detail設計模式的Core Data iPad應用程序上工作。 我正在嘗試在更新managedObjectContext
之后添加一行動畫。 當前,當我添加一個對象時,它僅出現在表格視圖中。 我正在使用Stanford Core Data Table View類。
這是我的添加對象委托的save方法:
- (void)addObjectSaveButtonTapped:(iPadAddObjectViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
[self setupFetchedResultsController];
}
這是我的setupFetchedResultsController
方法:
- (void)setupFetchedResultsController {
NSString *entityName = @"Object";
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"objectName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
[self performFetch];
}
這是performFetch
方法。
- (void)performFetch
{
_debug = YES;
if (self.fetchedResultsController) {
if (self.fetchedResultsController.fetchRequest.predicate) {
if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName, self.fetchedResultsController.fetchRequest.predicate);
} else {
if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName);
}
NSError *error;
[self.fetchedResultsController performFetch:&error];
if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
} else {
if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
}
[self.tableView reloadData];
}
有什么方法可以將動畫添加到對象添加中?
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:yourIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
UITableView
也有一個類似的方法insertSections:withRowAnimation:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.