iPhone之UISplitViewController
2015-04-07 00:11
281 查看
转自:http://blog.sina.com.cn/s/blog_4adf31ea0100qxoh.html
UISplitViewController类,只有在ipad中才可以使用。
ipad的屏幕比iphone大,所以在界面上,ipad比iphone多一个UISplitViewController,用来实现ipad在横屏时,分两栏显示所需要的界面,可以一边是目录一边是具体的内容。
首先创建一个Row1Detail和RootViewController,其中RootViewController继承UITableViewController。同事创建两个相应的xib文件。
AppDelegate 中的代码如下:
@interfacetestsplitviewAppDelegate : NSObject<UIApplicationDelegate> {
UIWindow
*window;
UISplitViewController
*splitView;
RootViewController
*root;
Row1Detail
*detail;
}
@property
(nonatomic,retain) IBOutlet
UIWindow *window;
@property (nonatomic,
retain) IBOutlet UISplitViewController*splitView;
@property
(nonatomic,retain)IBOutlet
RootViewController*root;
@property
(nonatomic,retain) IBOutlet
Row1Detail *detail;
@end
实现类:
-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
// Override point for customization afterapp launch.
[self.windowaddSubview:splitView.view];
[self.windowmakeKeyAndVisible];
return YES;
}
修改MainWindow.xib文件:添加UISplitViewController容器
绑定的事件如下:
RootViewController的代码如下:
@interface RootViewController :UITableViewController {
Row1Detail
*detail;
}
@property
(nonatomic,retain)IBOutlet
Row1Detail*detail;
@end
实现代码:
#import"RootViewController.h"
@implementationRootViewController
@synthesize
detail;
#pragma mark -
#pragma mark View lifecycle
-(void)viewDidLoad {
[superviewDidLoad];
self.clearsSelectionOnViewWillAppear=
NO;
self.contentSizeForViewInPopover
= CGSizeMake(320.0,600.0);
}
#pragma mark -
#pragma mark Table view data source
-(NSInteger)numberOfSectionsInTableView:(UITableView*)aTableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)aTableViewnumberOfRowsInSection:(NSInteger)section {
return 10;
}
-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath
*)indexPath {
static NSString *CellIdentifier =
@"CellIdentifier";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier]autorelease];
cell.accessoryType
= UITableViewCellAccessoryNone;
}
cell.textLabel.text = [NSString
stringWithFormat:@"Row %d", indexPath.row];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
-(void)tableView:(UITableView *)aTableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
detail.detailItem = [NSString
stringWithFormat:@"Row %d", indexPath.row];
}
Row1Detail的代码
@interface Row1Detail :UIViewController<UISplitViewControllerDelegate>{
UILabel
*Text1;
id detailItem;
}
@property
(nonatomic,retain)IBOutlet
UILabel *Text1;
@property
(nonatomic,retain) id
detailItem;
-(IBAction) click;
@end
实现代码如下:
#import "Row1Detail.h"
@implementation
Row1Detail
@synthesize
Text1;
@synthesize detailItem;
-(IBAction) click
{
NSLog(@"%@",Text1.text);
UIAlertView
*alert=[[UIAlertView alloc] initWithTitle:@"标题"message:@"22"
delegate:selfcancelButtonTitle:@"关"otherButtonTitles:nil];
[alert
show];
[alert
release];
Text1.text=@"11111111111";
}
-(void)setDetailItem:(id)newDetailItem
{
if (detailItem != newDetailItem) {
[detailItemrelease];
detailItem =[newDetailItem
retain];
Text1.text
=[detailItem description];
}
}
// Implement viewDidLoad to do additional setup after loading theview, typically from a nib.
-(void)viewDidLoad
{
[superviewDidLoad];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Overriden to allow anyorientation.
return YES;
}
UISplitViewController类,只有在ipad中才可以使用。
ipad的屏幕比iphone大,所以在界面上,ipad比iphone多一个UISplitViewController,用来实现ipad在横屏时,分两栏显示所需要的界面,可以一边是目录一边是具体的内容。
首先创建一个Row1Detail和RootViewController,其中RootViewController继承UITableViewController。同事创建两个相应的xib文件。
AppDelegate 中的代码如下:
@interfacetestsplitviewAppDelegate : NSObject<UIApplicationDelegate> {
UIWindow
*window;
UISplitViewController
*splitView;
RootViewController
*root;
Row1Detail
*detail;
}
@property
(nonatomic,retain) IBOutlet
UIWindow *window;
@property (nonatomic,
retain) IBOutlet UISplitViewController*splitView;
@property
(nonatomic,retain)IBOutlet
RootViewController*root;
@property
(nonatomic,retain) IBOutlet
Row1Detail *detail;
@end
实现类:
-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
// Override point for customization afterapp launch.
[self.windowaddSubview:splitView.view];
[self.windowmakeKeyAndVisible];
return YES;
}
修改MainWindow.xib文件:添加UISplitViewController容器
绑定的事件如下:
RootViewController的代码如下:
@interface RootViewController :UITableViewController {
Row1Detail
*detail;
}
@property
(nonatomic,retain)IBOutlet
Row1Detail*detail;
@end
实现代码:
#import"RootViewController.h"
@implementationRootViewController
@synthesize
detail;
#pragma mark -
#pragma mark View lifecycle
-(void)viewDidLoad {
[superviewDidLoad];
self.clearsSelectionOnViewWillAppear=
NO;
self.contentSizeForViewInPopover
= CGSizeMake(320.0,600.0);
}
#pragma mark -
#pragma mark Table view data source
-(NSInteger)numberOfSectionsInTableView:(UITableView*)aTableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)aTableViewnumberOfRowsInSection:(NSInteger)section {
return 10;
}
-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath
*)indexPath {
static NSString *CellIdentifier =
@"CellIdentifier";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier]autorelease];
cell.accessoryType
= UITableViewCellAccessoryNone;
}
cell.textLabel.text = [NSString
stringWithFormat:@"Row %d", indexPath.row];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
-(void)tableView:(UITableView *)aTableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
detail.detailItem = [NSString
stringWithFormat:@"Row %d", indexPath.row];
}
Row1Detail的代码
@interface Row1Detail :UIViewController<UISplitViewControllerDelegate>{
UILabel
*Text1;
id detailItem;
}
@property
(nonatomic,retain)IBOutlet
UILabel *Text1;
@property
(nonatomic,retain) id
detailItem;
-(IBAction) click;
@end
实现代码如下:
#import "Row1Detail.h"
@implementation
Row1Detail
@synthesize
Text1;
@synthesize detailItem;
-(IBAction) click
{
NSLog(@"%@",Text1.text);
UIAlertView
*alert=[[UIAlertView alloc] initWithTitle:@"标题"message:@"22"
delegate:selfcancelButtonTitle:@"关"otherButtonTitles:nil];
[alert
show];
[alert
release];
Text1.text=@"11111111111";
}
-(void)setDetailItem:(id)newDetailItem
{
if (detailItem != newDetailItem) {
[detailItemrelease];
detailItem =[newDetailItem
retain];
Text1.text
=[detailItem description];
}
}
// Implement viewDidLoad to do additional setup after loading theview, typically from a nib.
-(void)viewDidLoad
{
[superviewDidLoad];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Overriden to allow anyorientation.
return YES;
}
相关文章推荐
- iOS:iPad和iPhone开发的异同(UIPopoverController、UISplitViewController)
- UISplitViewController in portrait on iPhone shows detail VC instead of master
- iOS UISplitViewController 开发(iOS8)
- UISplitViewController在Portrait时也为分割窗口
- UISplitViewController - iPad分屏视图控制器
- 分割视图控制器(UISplitViewController)
- ipad 自定义UISplitViewController
- iPad for iPhone Developers 101 in iOS 6: UISplitView Tutorial
- UISplitViewController
- UISplitViewController
- ipa 开发常用控件 : UISplitViewController , UIPopoverController
- UISplitViewController 分割视图控制器,自定义左右视图控制器视图大小
- UISplitViewController 只能用在最开始的 window.rootViewController
- iOS:分割控制器UISplitViewcontroller
- IOS控件之分隔条控制器UISplitViewController
- UISplitViewController基本使用方法
- iPad 如何创建UISplitViewController应用程序
- UISplitViewController的使用
- IPad专有API UISplitViewController开发菜单浏览demo
- UISplitViewController的使用