3D Touch Objective-C Example
suggest changeThis is the iOS 9 peek-and-pop API. The view controller must adopt UIViewControllerPreviewingDelegate. location is in sourceView (self.view), so convert it into the table before hit-testing, and convert the cell rectangle back before assigning sourceRect.
Objective-C
- (void)viewDidLoad {
[super viewDidLoad];
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:self sourceView:self.view];
}
}
// Peek
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
viewControllerForLocation:(CGPoint)location {
CGPoint point = [self.tableView convertPoint:location fromView:self.view];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
if (indexPath == nil) {
return nil;
}
Country *country = [self countryForIndexPath:indexPath];
CountryCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (country && cell) {
previewingContext.sourceRect = [self.tableView convertRect:cell.frame toView:self.view];
UINavigationController *navController = [self.storyboard instantiateViewControllerWithIdentifier:@"UYLCountryNavController"];
[self configureNavigationController:navController withCountry:country];
return navController;
}
return nil;
}
// Pop
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
commitViewController:(UIViewController *)viewControllerToCommit {
[self showDetailViewController:viewControllerToCommit sender:self];
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents