我目前正在我的应用程序中实现 Peek and Pop。我有一个UITableView
包含一些数据。我编写了这个函数来处理 Peek:
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
// check if we're not already displaying a preview controller
if ([self.presentedViewController isKindOfClass:[DetailViewController class]]) {
return nil;
}
NSLog(@"Test");
CGPoint cellPostion = [self.tableView convertPoint:location fromView:self.view];
NSIndexPath *path = [self.tableView indexPathForRowAtPoint:cellPostion];
if (path) {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
NSDictionary *data = [self.restaurants objectAtIndex:path.row];
// shallow press: return the preview controller here (peek)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
DetailViewController *previewController = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
previewController.restaurant = data;
[previewingContext setSourceRect:cell.frame];
return previewController;
}
return nil;
}
是这样构造的UITableView
:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = @"Overview";
self.restaurants = [sRestaurants fetchAll];
NSLog(@"%@", self.subscriptions);
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
但是,现在,它甚至没有登录Test
到控制台。我究竟做错了什么?