iOS iPad开发~demo
来源:互联网 发布:java学生管理系统集合 编辑:程序博客网 时间:2024/06/05 16:02
//联系人:石虎 QQ: 1224614774昵称:嗡嘛呢叭咪哄
/**
注意点: 1.看 GIF 效果图.
2.看连线视图的效果图.
3.看实现代码(直接复制实现效果).
*/
一、GIF 效果图:
二、连线视图的效果图:
图1:
图2:
三、实现代码:
=========================
===================================================
====================控制器1:AppDelegate.h
// Created by 石虎 on 2017/8/7.
// Copyright © 2017年 shihu. All rights reserved.
//
#import <UIKit/UIKit.h>
@class SHDetailViewController,SHRootTableViewController;
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic)UIWindow *window;
//详情界面
@property(nonatomic,strong)SHDetailViewController *detailVC;
//左侧边栏的表格界面
@property(nonatomic,strong)SHRootTableViewController *rootVC;
//边栏控制器(自动添加了手势自动弹回功能)
@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"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.rootVC = [[SHRootTableViewControlleralloc]initWithStyle:UITableViewStylePlain];
self.rootVC.navigationItem.title = @"导航视图";
UINavigationController *rootNav = [[UINavigationControlleralloc]initWithRootViewController:self.rootVC];
self.detailVC = [[SHDetailViewControlleralloc]init];
self.detailVC.navigationItem.title = @"详情视图";
UINavigationController *detailNav = [[UINavigationControlleralloc]initWithRootViewController:self.detailVC];
// 使用iPad专用控件实现分栏效果
self.spiltVC = [[UISplitViewControlleralloc]init];
//设置分栏试图先后顺序决定了左右关系
self.spiltVC.viewControllers =@[rootNav,detailNav];
self.spiltVC.delegate =self.detailVC;
// 设置为窗口的跟视图控制器
self.window.rootViewController =self.spiltVC;
returnYES;
}
=========================
===================================================
====================控制器2:
// iPad开发dome
//
// Created by 石虎 on 2017/8/7.
// Copyright © 2017年 shihu. All rights reserved.
//
#import "SHRootTableViewController.h"//左侧边栏的表格界面
#import "SHDetailViewController.h"
#import "AppDelegate.h"
@interface SHRootTableViewController ()
// 图片名称数组
@property(nonatomic,strong)NSArray *imgTitleArr;
// 图片数组
@property(nonatomic,strong)NSArray *imgArr;
@end
@implementation SHRootTableViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.imgTitleArr =@[@"大众",@"法拉利",@"宝马",@"奔驰",@"JEEP",@"迈巴赫",@"兰博基尼"];
//通过循环将图片数组初始化
NSMutableArray *arr = [[NSMutableArrayalloc]init];
for (int i =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 {
static NSString *identifier =@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//缓存池
if (cell ==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
cell.textLabel.text = self.imgTitleArr[indexPath.row];
return cell;
}
//跳转
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 得到在Appdele中实例化的DetailViewController对象的内存
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 <UIKit/UIKit.h>
@interface SHDetailViewController :UIViewController
//显示图片
@property (strong,nonatomic)IBOutletUIImageView *imgView;
@end
//
// Created by 石虎 on 2017/8/7.
// Copyright © 2017年 shihu. All rights reserved.
//
#import "SHDetailViewController.h"
#import "AppDelegate.h"
#import "SHRootTableViewController.h"//左侧边栏的表格界面
@interface SHDetailViewController ()<UISplitViewControllerDelegate,UIPopoverControllerDelegate>
@end
@implementation SHDetailViewController
- (void)viewDidLoad {
[superviewDidLoad];
//导航栏
self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"主菜单"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(showPopOverController:)];
AppDelegate *app = (AppDelegate *)[UIApplicationsharedApplication].delegate;
app.spiltVC.displayModeButtonItem.title =@"显示导航栏";
self.navigationItem.leftBarButtonItem = app.spiltVC.displayModeButtonItem;
}
//回调方法
-(void)showPopOverController:(UIBarButtonItem *)sender
{
//左侧边栏的表格界面
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(@"弹出视图已经隐藏");
}
#pragma mark - UISplitViewControllerDelegate
// 左侧导航栏将要出现或隐藏时回调此方法
-(void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
{
// 左侧导航栏隐藏
if (displayMode == UISplitViewControllerDisplayModePrimaryHidden)
{
NSLog(@"左侧导航将要隐藏");
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.spiltVC.displayModeButtonItem.title = @"显示导航栏";
//
svc.displayModeButtonItem.title = @"显示导航栏";
self.navigationItem.leftBarButtonItem = app.spiltVC.displayModeButtonItem;
}
else if (displayMode == UISplitViewControllerDisplayModePrimaryOverlay)
{
NSLog(@"左侧导航覆盖到详情视图上");
}
else if (displayMode == UISplitViewControllerDisplayModeAllVisible)
{
NSLog(@"左侧导航全部显示");
self.navigationItem.leftBarButtonItem =nil;
}
else
{
NSLog(@"自动显示");
}
}
@end
谢谢!!!
- iOS iPad开发~demo
- iOS ipad和iphone兼容~demo
- iOS开发 - 气泡控制器 IPAD
- iOS iPad开发~笔记 01
- iOS iPad开发~笔记 02
- iOS开发--官方demo
- [iOS]wallet开发demo
- iOS(iPhone,iPad))开发(Obje…
- ios-day25-02(iPad开发之UIPopoverController)
- ios-day25-03(iPad开发之Modal)
- iOS应用开发视频教程笔记iPad Apps
- 捏拢Demo: SimpleGestures-iPad
- iOS 开发官方 Demo 大全
- IOS越狱开发好demo
- (0061)iOS开发之iPad开发:UISplitViewController分割视图控制器
- iPad应用开发实践指南:菜鸟如何用ios 5开发ipad上的复杂应用程序
- ipad开发
- iPad开发
- C++之循环结构
- HDU_3791 二叉搜索树
- 《leetCode》:Remove Duplicates from Sorted Array
- 符号定义伪指令
- 设计模式-职责链模式
- iOS iPad开发~demo
- ubuntu python 安装使用的问题
- 用Huffman树实现文件压缩与解压
- 原地交换两个变量的值
- def自定函数 和参数顺序
- 敌兵布阵(线段树)
- MySQL的相关应用
- 欢迎使用CSDN-markdown编辑器
- 【Machine Learning】笔记:无监督学习