//实现UIViewControllerPreviewingDelegate代理方法
@interface InfoListTableViewController : UITableViewController <UIViewControllerPreviewingDelegate>
@end
//
// InfoListTableViewController.m
// Test3DTouch
//
// Created by ios01 on 15/12/16.
// Copyright © 2015年 ios01. All rights reserved.
//
#import "InfoListTableViewController.h"
#import "InfoDetailViewController.h"
@interface InfoListTableViewController ()
@property (nonatomic, retain) NSMutableArray *arrDatas;
@property (strong, nonatomic) IBOutlet UITableView *showTableView;
@end
@implementation InfoListTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setArrDatas:[NSMutableArray arrayWithArray:@[@"1111", @"2222"]]];
[_showTableView reloadData];
// 注册pep代理方法
[self registerForPreviewingWithDelegate:self sourceView:self.view];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
NSLog(@"");
return [_arrDatas count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Configure the cell...
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell.textLabel setText:[_arrDatas objectAtIndex:indexPath.row]];
return cell;
}
#pragma mark - peek和pop代理方法
//预览界面代理方法
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)context viewControllerForLocation:(CGPoint) point
{
InfoDetailViewController *childVC = [[InfoDetailViewController alloc] initWithNibName:@"InfoDetailViewController" bundle:nil];
NSIndexPath* indexpath = [_showTableView indexPathForRowAtPoint:point];
if (indexpath.row==0) {
[childVC setStrUrl:@"https://www.baidu.com"];
}
else {
[childVC setStrUrl:@"http://www.sina.com"];
}
// UIViewController *childVC = [[UIViewController alloc] init];
childVC.preferredContentSize = CGSizeMake(0.0f,300.0f);
CGRect rect = CGRectMake(10, point.y - 10, self.view.frame.size.width - 20,20);
context.sourceRect = rect;
return childVC;
}
//继续按压后,跳转到需要展示的界面
- (void)previewingContext:(id<UIViewControllerPreviewing>)context commitViewController:(UIViewController*)vc
{
[self showViewController:vc sender:self];
}
@end