Oc iPad与iPhone兼容~demo
来源:互联网 发布:算法c语言实现高清pdf 编辑:程序博客网 时间:2024/05/22 00:46
图1~iphone:
图2~ipad:
实现代码:
控制器1:AppDelegate.h
#import <UIKit/UIKit.h>@interface AppDelegate :UIResponder <UIApplicationDelegate>@property (strong,nonatomic) UIWindow *window;@property(nonatomic,strong)UISplitViewController *splitVC; // 左侧的导航栏控制器@property(nonatomic,strong)NSArray *detailNavArr; // 存储iPad运行时,右侧详情导航视图控制器的数组@property(nonatomic,strong)NSArray *detailVCArr; // 存储iPhone运行时,右侧需要进栈的视图控制器数组@end
控制器1: AppDelegate.m
#import "AppDelegate.h"#import "SHMasterTableViewController.h"//主控制器#import "SHFirstViewController.h"#import "SHSecondViewController.h"#import "SHThirdViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //主控制器 SHMasterTableViewController *masterVC = [[SHMasterTableViewControlleralloc] initWithStyle:UITableViewStylePlain]; //导航栏 UINavigationController *masterNav = [[UINavigationControlleralloc] initWithRootViewController:masterVC]; SHFirstViewController *firstVC = [[SHFirstViewControlleralloc] init]; SHSecondViewController *secVC = [[SHSecondViewControlleralloc] init]; SHThirdViewController *thirdVC = [[SHThirdViewControlleralloc] init]; // 判断如果是iPad运行 if([UIDevicecurrentDevice].userInterfaceIdiom ==UIUserInterfaceIdiomPad) { //把第一控制器添加到导航栏 UINavigationController *firstNav = [[UINavigationControlleralloc] initWithRootViewController:firstVC]; NSLog(@"----->>> %p",firstNav); //把第二控制器添加到导航栏 UINavigationController *secNav = [[UINavigationControlleralloc] initWithRootViewController:secVC]; //把第三控制器添加到导航栏 UINavigationController *thirdNav = [[UINavigationControlleralloc] initWithRootViewController:thirdVC]; //添加到存储iPad运行时,右侧详情导航视图控制器的数组中 self.detailNavArr =@[firstNav,secNav,thirdNav]; //初始化左侧的导航栏控制器 self.splitVC = [[UISplitViewControlleralloc] init]; self.splitVC.viewControllers =@[masterNav,firstNav]; self.window.rootViewController = self.splitVC; }#pragma mark - iPhone运行 else { self.detailVCArr =@[firstVC,secVC,thirdVC]; self.window.rootViewController = masterNav; } returnYES;}
控制器2: SHMasterTableViewController.m
#import "SHMasterTableViewController.h"#import "AppDelegate.h"@interface SHMasterTableViewController ()//@property(nonatomic,strong)NSArray *titleArr;@end@implementation SHMasterTableViewController- (void)viewDidLoad { [superviewDidLoad]; //显示cell上的数据 self.titleArr =@[@"运动",@"菜系",@"游戏"];}#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { returnself.titleArr.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier =@"CELL"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; //缓存池 if (cell ==nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } cell.textLabel.text = self.titleArr[indexPath.row]; return cell;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ AppDelegate *appDele = (AppDelegate *)[UIApplication sharedApplication].delegate; // 如果是iPad运行 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { appDele.splitVC.viewControllers = @[self.navigationController,appDele.detailNavArr[indexPath.row]]; }else{// iPhone运行 [self.navigationController pushViewController:appDele.detailVCArr[indexPath.row] animated:YES]; }}@end
控制器3: SHFirstViewController.m
#import "SHFirstViewController.h"#import "SHDetailViewController.h"//详情控制器@interface SHFirstViewController ()@end@implementation SHFirstViewController- (void)viewDidLoad { [superviewDidLoad]; //手势 UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(gotoDetailVC)]; tap.numberOfTapsRequired =2; [self.viewaddGestureRecognizer:tap];}//回调手势-(void)gotoDetailVC{ SHDetailViewController *detailVC = [[SHDetailViewControlleralloc] init]; [self.navigationControllerpushViewController:detailVCanimated:YES]; NSLog(@"详情控制器----->%p",self.navigationController);}@end
控制器4: SHDetailViewController.m
#import "SHDetailViewController.h"@interface SHDetailViewController ()@end@implementation SHDetailViewController- (void)viewDidLoad { [superviewDidLoad]; NSLog(@"我是第 详情 大控制器"); }@end
控制器5: SHSecondViewController.m
#import "SHSecondViewController.h"@interface SHSecondViewController ()@end@implementation SHSecondViewController- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"我是第 二 大控制器");}@end
控制器6: SHThirdViewController.m
#import "SHThirdViewController.h"@interface SHThirdViewController ()@end@implementation SHThirdViewController- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"我是第 三 大控制器");}@end
阅读全文
0 0
- Oc iPad与iPhone兼容~demo
- iOS ipad和iphone兼容~demo
- cocod2d 兼容iphone/ipad 问题
- ipad/iphone兼容小技巧
- iphone 与 ipad 分辨率
- 让UIAlertController同时兼容iphone和ipad
- iOS数据分享(兼容iPad,iphone)
- iPhone/iPad高级应用与手游开发学习笔记:AVAudioPlayer学习(音频播放demo)
- iphone 与 ipad 程序图标
- iphone与ipad历代分辨率
- ipad与iphone区别之一
- iPad与iPhone屏幕布局
- iPhone/iPad高级应用与手游开发学习笔记:sqlite3学习(简单英文生词本demo)
- iphone/ipad 自动化测试 Demo(XCode4.5.1)
- iPhone与iPad开发的区别
- iPhone 4与iPad开发基础教程
- iphone 与 ipad 的自动布局
- (iPhone/iPad)文件上传与下载
- virtualenv在ubuntu上的使用
- Oc iPad开发~dome
- HMM隐马尔科夫模型例题讲解 加深印象
- 图形用户界面
- (机器学习基石)Machine Learning Foundations:Lecture 2
- Oc iPad与iPhone兼容~demo
- java菱形
- sql查询过程
- Oc 正则表达式 demo
- IDEA Jrebel 插件
- JSP页面出错,不知道怎么改
- python:2017.10.31
- Oc 正则表达式~常用符号
- 字典(python)