ios-使用iPad专用API(UISplitViewController)控制器
2014-09-08 16:22
776 查看
iPhone和iPad都使用同一个操作系统——ios,因此,它们的API基本上是一样的,但有一些是iPad专用的,比如UISplitViewController控制器,UISplitViewController控制器用于呈现“屏幕分栏”类型的视图。UISplitViewController有两个视图控制器,一个是MasterViewController,另一个是DetailViewController,iPad在横屏的情况下,两者都显示出来;iPad在竖屏的情况下,MasterViewController隐藏,只有DetailViewController显示出来。
代码实现如下:
至此,iPad专用API(UISplitViewController)控制器介绍已经完毕,程序运行效果图如下:
iPad 横屏效果图:
iPad 竖屏效果图:
代码实现如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { MasterViewController *masterViewCtl = [[MasterViewController alloc] init]; DetailViewController *detailViewCtl = [[DetailViewController alloc] init]; UINavigationController *navCtl = [[UINavigationController alloc] initWithRootViewController:masterViewCtl]; _splitViewCtl = [[KFSplitViewController alloc] init]; [_splitViewCtl addChildViewController:navCtl]; [_splitViewCtl addChildViewController:detailViewCtl]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = _splitViewCtl; [self.window makeKeyAndVisible]; [masterViewCtl release]; [detailViewCtl release]; [navCtl release]; [_splitViewCtl release]; return YES; }
// // KFSplitViewController.h // #import <UIKit/UIKit.h> @interface KFSplitViewController : UISplitViewController @end
// // KFSplitViewController.m // #import "KFSplitViewController.h" @interface KFSplitViewController () @end @implementation KFSplitViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
// // MasterViewController.h // #import <UIKit/UIKit.h> @interface MasterViewController : UITableViewController { NSMutableArray *mutArr; int iSelect; } @end
// // MasterViewController.m // #import "MasterViewController.h" @interface MasterViewController () @end @implementation MasterViewController - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; mutArr = [[NSMutableArray alloc] initWithCapacity:20]; for (int i = 0; i < 10; i ++) { NSString *str = [NSString stringWithFormat:@"Cell_%d",i]; [mutArr addObject:str]; } self.title = @"Master View"; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *indentifer = @"myCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer] autorelease]; } int iRow = [indexPath row]; NSString *str = [mutArr objectAtIndex:iRow]; cell.textLabel.text = str; if (iSelect == iRow) cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; else cell.accessoryType = UITableViewCellAccessoryNone; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { iSelect = [indexPath row]; NSString *str = [mutArr objectAtIndex:iSelect]; [[NSNotificationCenter defaultCenter] postNotificationName:@"MasterMessageToDetail" object:str userInfo:nil]; [tableView reloadData]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { } else if (editingStyle == UITableViewCellEditingStyleInsert) { } } - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } @end
// // DetailViewController.h // #import <UIKit/UIKit.h> @interface DetailViewController : UIViewController { UILabel *label; } @end
// // DetailViewController.m // #import "DetailViewController.h" @interface DetailViewController () @end @implementation DetailViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)dealloc { // 取消观察者 [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } - (void)viewDidLoad { [super viewDidLoad]; // 注册观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handl:) name:@"MasterMessageToDetail" object:nil]; [self initButton]; } - (void)initButton { label = [[UILabel alloc] initWithFrame:CGRectMake(300, 200, 150, 40)]; label.backgroundColor = [UIColor whiteColor]; label.layer.cornerRadius = 5.0f; label.layer.masksToBounds = 5.0f; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blackColor]; [self.view addSubview:label]; [label release]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(300, 250, 150, 40)]; btn.backgroundColor = [UIColor whiteColor]; btn.layer.cornerRadius = 5.0f; btn.showsTouchWhenHighlighted = YES; [btn setTitle:@"Detail View" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [self.view addSubview:btn]; [btn release]; } - (void)handl:(NSNotification *)notifi { NSString *str = [notifi object]; label.text = str; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
至此,iPad专用API(UISplitViewController)控制器介绍已经完毕,程序运行效果图如下:
iPad 横屏效果图:
iPad 竖屏效果图:
相关文章推荐
- 【IOS】分隔视图控制器 (UISplitViewController)
- ipad UISplitViewController 导航视图控制器标题设置
- [iOS开发]UISplitViewController的使用
- IPad专有API UISplitViewController开发菜单浏览demo
- iOS:iPad和iPhone开发的异同(UIPopoverController、UISplitViewController)
- iOS:分割控制器UISplitViewcontroller
- iOS 6编程--分割视图控制器(UISplitViewController)和Master-Detail Application模板
- iOS UISplitViewController 使用教学
- 【iOS开发-107】UISplitViewController:如何取得master和detail控制器,核心在于如何运用代理
- ios-使用iPad专用API(UIPopoverController)控制器
- iPad开发专有API-UIPopoverViewController和UISplitViewController
- IOS控件之分隔条控制器UISplitViewController
- UISplitViewController - iPad分屏视图控制器
- UISplitViewController - iPad分屏视图控制器
- UI: 用 UISplitViewController 显示 Master-Detail 视图 ;使用 UIPageViewController 启用分页;使用 UIPopoverController 显示弹出画面(弹出框)
- iOS开发UI基础—32直接使用UITableView Controller
- [ios]ipad下的splitViewController 让你的APP看起来酷酷的!
- iPad 用xib如何创建UISplitViewController应用程序
- 学习IOS开发UI篇--UICollectionViewController的基本使用
- IOS UISplitViewController之 解决 密码框添加之后 调用子视图的转向方法之时 对象为空