您的位置:首页 > 运维架构

Peek and Pop新功能展示

2015-12-16 23:33 405 查看


//实现[b]UIViewControllerPreviewingDelegate代理方法[/b]



@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];

[b]//
注册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

[/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: