//聯(lián)系人:石虎QQ: 1224614774昵稱:嗡嘛呢叭咪哄
/**
注意點(diǎn): 1.看 GIF 效果圖.
2.看連線視圖的效果圖.
3.看實(shí)現(xiàn)代碼(直接復(fù)制實(shí)現(xiàn)效果).
*/
一咆瘟、GIF 效果圖:
二佳簸、連線視圖的效果圖:
圖1:
圖2:
三、實(shí)現(xiàn)代碼:
=========================
===================================================
====================
控制器1:AppDelegate.h
//? Created by石虎on 2017/8/7.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import
@classSHDetailViewController,SHRootTableViewController;
@interfaceAppDelegate :UIResponder
@property(strong,nonatomic)UIWindow*window;
//詳情界面
@property(nonatomic,strong)SHDetailViewController*detailVC;
//左側(cè)邊欄的表格界面
@property(nonatomic,strong)SHRootTableViewController*rootVC;
//邊欄控制器(自動(dòng)添加了手勢自動(dòng)彈回功能)
@property(nonatomic,strong)UISplitViewController*spiltVC;
@end
==========
======
====
控制器1:AppDelegate.m
//
//? Created by石虎on 2017/8/7.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import"AppDelegate.h"
#import"SHRootTableViewController.h"
#import"SHDetailViewController.h"
@interfaceAppDelegate()
@end
@implementationAppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
self.rootVC= [[SHRootTableViewControlleralloc]initWithStyle:UITableViewStylePlain];
self.rootVC.navigationItem.title=@"導(dǎo)航視圖";
UINavigationController*rootNav = [[UINavigationControlleralloc]initWithRootViewController:self.rootVC];
self.detailVC= [[SHDetailViewControlleralloc]init];
self.detailVC.navigationItem.title=@"詳情視圖";
UINavigationController*detailNav = [[UINavigationControlleralloc]initWithRootViewController:self.detailVC];
//使用iPad專用控件實(shí)現(xiàn)分欄效果
self.spiltVC= [[UISplitViewControlleralloc]init];
//設(shè)置分欄試圖先后順序決定了左右關(guān)系
self.spiltVC.viewControllers =@[rootNav,detailNav];
self.spiltVC.delegate =self.detailVC;
//設(shè)置為窗口的跟視圖控制器
self.window.rootViewController =self.spiltVC;
returnYES;
}
=========================
===================================================
====================
控制器2:
//? iPad開發(fā)dome
//
//? Created by石虎on 2017/8/7.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import"SHRootTableViewController.h"http://左側(cè)邊欄的表格界面
#import"SHDetailViewController.h"
#import"AppDelegate.h"
@interfaceSHRootTableViewController()
//圖片名稱數(shù)組
@property(nonatomic,strong)NSArray*imgTitleArr;
//圖片數(shù)組
@property(nonatomic,strong)NSArray*imgArr;
@end
@implementationSHRootTableViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.imgTitleArr=@[@"大眾",@"法拉利",@"寶馬",@"奔馳",@"JEEP",@"邁巴赫",@"蘭博基尼"];
//通過循環(huán)將圖片數(shù)組初始化
NSMutableArray*arr = [[NSMutableArrayalloc]init];
for(inti =1; i <=7; i++) {
NSString*imgName = [NSStringstringWithFormat:@"car%d.jpg",i];
UIImage*img = [UIImageimageNamed:imgName];
[arr addObject:img];
}
//
self.imgArr = [arr copy];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
returnself.imgArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
staticNSString *identifier =@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//緩存池
if(cell ==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
cell.textLabel.text =self.imgTitleArr[indexPath.row];
returncell;
}
//跳轉(zhuǎn)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//得到在Appdele中實(shí)例化的DetailViewController對(duì)象的內(nèi)存
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
SHDetailViewController *detaiVC = appDelegate.detailVC;
detaiVC.imgView.image =self.imgArr[indexPath.row];
}
@end
=========================
===================================================
====================
控制器3:SHDetailViewController.h
//? Created by石虎on 2017/8/7.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import
@interfaceSHDetailViewController :UIViewController
//顯示圖片
@property(strong,nonatomic)IBOutletUIImageView*imgView;
@end
控制器3:SHDetailViewController.m
//
//? Created by石虎on 2017/8/7.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import"SHDetailViewController.h"
#import"AppDelegate.h"
#import"SHRootTableViewController.h"http://左側(cè)邊欄的表格界面
@interfaceSHDetailViewController()
@end
@implementationSHDetailViewController
- (void)viewDidLoad {
[superviewDidLoad];
//導(dǎo)航欄
self.navigationItem.rightBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@"主菜單"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(showPopOverController:)];
AppDelegate*app = (AppDelegate*)[UIApplicationsharedApplication].delegate;
app.spiltVC.displayModeButtonItem.title=@"顯示導(dǎo)航欄";
self.navigationItem.leftBarButtonItem =? app.spiltVC.displayModeButtonItem;
}
//回調(diào)方法
-(void)showPopOverController:(UIBarButtonItem *)sender
{
//左側(cè)邊欄的表格界面
SHRootTableViewController *rootVC = [[SHRootTableViewController alloc] initWithStyle:UITableViewStylePlain];
//彈出視圖
UIPopoverController *popCtl = [[UIPopoverController alloc] initWithContentViewController:rootVC];
//彈出視圖大小
popCtl.popoverContentSize = CGSizeMake(200,300);
popCtl.backgroundColor = [UIColor yellowColor];
popCtl.delegate =self;
//彈出該視圖
[popCtl presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
#pragma mark - UIPopoverControllerDelegate
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
NSLog(@"將要隱藏彈出視圖");
returnYES;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
NSLog(@"彈出視圖已經(jīng)隱藏");
}
#pragma mark - UISplitViewControllerDelegate
//左側(cè)導(dǎo)航欄將要出現(xiàn)或隱藏時(shí)回調(diào)此方法
-(void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
{
//左側(cè)導(dǎo)航欄隱藏
if(displayMode == UISplitViewControllerDisplayModePrimaryHidden)
{
NSLog(@"左側(cè)導(dǎo)航將要隱藏");
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.spiltVC.displayModeButtonItem.title =@"顯示導(dǎo)航欄";
//
svc.displayModeButtonItem.title =@"顯示導(dǎo)航欄";
self.navigationItem.leftBarButtonItem = app.spiltVC.displayModeButtonItem;
}
elseif(displayMode == UISplitViewControllerDisplayModePrimaryOverlay)
{
NSLog(@"左側(cè)導(dǎo)航覆蓋到詳情視圖上");
}
elseif(displayMode == UISplitViewControllerDisplayModeAllVisible)
{NSLog(@"左側(cè)導(dǎo)航全部顯示");
self.navigationItem.leftBarButtonItem =nil;
}else{NSLog(@"自動(dòng)顯示");}}
@end
謝謝!!!