iphone:UISplitView

简介:

 UINavigationController *nc = [self.splitViewController.viewControllers  lastObject];

    self.detailViewController = (SplitViewDetailViewController *)[nc topViewController];

有一个splitViewController属性,其viewControllers为一个含两个ViewController的数组,0-left,1-right in landscape

 

 

看文档:https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UISplitViewController_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009277

The array in this property must contain exactly two view controllers. The view controllers are presented left-to-right in the split view interface when it is in a landscape orientation. Thus, the view controller at index 0 is displayed on the left side and the view controller at index 1 is displayed on the right side of the interface.

The first view controller in this array is typically hidden when the device is in a portrait orientation. Assign a delegate object to the receiver if you want to coordinate the display of this view controller using a popover.

 

创建过程:

在StoryBoard中让Master Detail都Embed in navi..

然后先在AppDelegate的

didFinishLaunchingWithOptions中添加代码,使得splitView的delegate为DetailViewController

复制代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
    splitViewController.delegate = (id)navigationController.topViewController;
    return YES;
}
复制代码

在MasterVC中取得DetailVC

 

@property (strongnonatomicDetailViewController *detailViewController;

viewDidLoad:

    UINavigationController *nc = [self.splitViewController.viewControllers  lastObject];

    self.detailViewController = (DetailViewController *)[nc topViewController];

 

self.detailViewController.detailItem =  xxxx;

 

在DetailVC中,当然要遵循<UISplitViewControllerDelegate>

 

@property (strongnonatomicid detailItem;//in .h

@property (strong, nonatomic) UIPopoverController *masterPopoverController;//in .m

 

- (void)setDetailItem:(id)newDetailItem {        

    // Update the view.  

}

复制代码
#pragma mark - Split view

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    barButtonItem.title = @"列表";
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.masterPopoverController = popoverController;
}


- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // Called when the view is shown again in the split view, invalidating the button and popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.masterPopoverController = nil;
}
复制代码

 

    若DetailVC不止是一个ViewController,我们可以使MasterVC遵循<UISplitViewControllerDelegate>,实现其委托方法;让DetailVC遵循自定义的协议,其功能是使在land和port时隐藏\显示 调出popover的barItem

 

然后在tableView:didSelectRowAtIndexPath: 中实例化相应的DetailVC,

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];

    FirstDetailViewController *newDetailViewController = [storyboard instantiateViewControllerWithIdentifier:@"v1"];

    detailViewController = newDetailViewController;

 当然也可以通过StoryBoard中的Segue代替实现实例化功能

 

本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2012/05/12/2497266.html,如需转载请自行联系原作者

相关文章
|
7月前
|
网络安全 开发工具 数据安全/隐私保护
ipa 如何安装到 iphone
ipa 如何安装到 iphone
|
传感器 编解码 算法
拿到iPhone X 后,你首先要做的10件事!
据 iPhone X 全球正式发售也近两周了,国内外媒体对这款代表着苹果未来10年发展方向的新机,已有了不少评测和总结,科技君今天就给各位果粉小伙伴们整理下有关 iPhone X 上手的十个必备技巧,助你发挥出它全部的潜力和乐趣。
211 0
拿到iPhone X 后,你首先要做的10件事!
|
人工智能 自动驾驶 iOS开发
苹果患上iPhone依赖症
苹果患上iPhone依赖症
138 0
苹果患上iPhone依赖症
|
编解码 iOS开发 芯片
iPhone SE2发布,它跟iPhone 8有什么不同?
昨天晚上,苹果又双叕在官网直接上架了新产品,它就是果粉们期待已久的第二代iPhone SE。
292 0
iPhone SE2发布,它跟iPhone 8有什么不同?
|
Shell iOS开发
Iphone攻与防-一
iphone-越狱机Hook APP 价值
1653 0
|
iOS开发 编解码
为新 iPhone X 添加启动图片
Xcode9 的 iPhone X 启动图片 iPhone X 启动图片大小: Portrait size : 1125px × 2436px Landscape size:2436px × 1125px 在 Xcode9 中位置: iPhone X 启动图片.
1062 0

热门文章

最新文章