我的应用程序在 Core Data 对象中存储了不同的属性。它们都显示在 UITableView 中,如果单击单元格,则会显示 DetailView。Master-Detail-XCode-Template 中的常见内容。
现在我想用 peek and pop 实现 3D Touch。就像在邮件应用程序中一样,3D 触摸一个单元格,获得预览,按下更深,弹出细节。
到目前为止我得到了这个工作,但我不知道如何传递相应的数据
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
和
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
到另一个 DetailViewController。
如果您只是单击单元格(没有 3D 触摸),我会交出数据
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
我正在使用一个
id detailItem
在每个 ViewController 中,我都为其设置了相应的对象。
因此,我尝试获得与工作类似的东西,因此在我的 DetailViewController 中,我的“detailItem”需要来自选定(3D 触摸)单元格的相应核心数据对象。
感谢帮助 !