ipad的屏幕比iphone大,所以在界面上,ipad比iphone多一个UISplitVIEwController,用来实现ipad在横屏时,分两栏显示所需要的界面,可以一边是目录一边是具体的内容。下面我将详细的阐述UISplitVIEwController在ipad中的使用。
首先是创建一个工程:ipad.demo.
然后创建一个DetailVIEwController和RootVIEwController,其中RootVIEwController继承UItableVIEwController。同事创建两个相应的xib文件。删除ipad_demoVIEwController.相应的类列表如下:
然后修改ipad_demoAppDelegate:
.h文件:
#import <UIKit/UIKit.h>
#import "RootVIEwController.h"
#import "DetailVIEwController.h"
@class ipad_demoVIEwController;@interface ipad_demoAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UISplitVIEwController *splitVIEwController;
RootVIEwController *rootVIEwController;
DetailVIEwController *detailVIEwController;
}@property (nonatomic,retain) IBOutlet UIWindow *window;
@property (nonatomic,retain) IBOutlet UISplitVIEwController *splitVIEwController;
@property (nonatomic,retain) IBOutlet RootVIEwController *rootVIEwController;
@property (nonatomic,retain) IBOutlet DetailVIEwController *detailVIEwController;
@end
.m文件:
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// OverrIDe point for customization after app launch.
[window addSubvIEw:splitVIEwController.vIEw];
[window makeKeyAndVisible];return YES;
}
修改MainWindow.xib文件:
添加UISplitVIEwController容器:
IB中的控件和相应的事件相联系:连接过程是按住control键,然后点击ipad_demo App Delegate,连接到Split VIEw Controller,然后选择自定义的事件即可,最后的结果如下:
最后在把相应的容器换成自定义的容器:实现的方法是
最后的结果是:
现在我们在实现DetailVIEwController:
首先修改其相应的文件:.h文件修改如下:
#import <UIKit/UIKit.h>
@interface DetailVIEwController : UIVIEwController {
IBOutlet UILabel *lable;
IBOutlet UISwitch *switch1;
NSIndexPath *index;
}
-(voID)deetail:(ID)sender;
@property (nonatomic,retain) UILabel *lable;
@property (nonatomic,retain) UISwitch *switch1;
@end
.m文件修改如下:
#import "DetailVIEwController.h"
@implementation DetailVIEwController
@synthesize lable,switch1;
- (voID)vIEwDIDLoad {
[super vIEwDIDLoad];
}
-(voID)vIEwWillAppear:(BOol)animated
{}
-(voID)deetail:(ID)sender
{
index=sender;
self.lable.text=[Nsstring stringWithFormat:@"Row %d,section %d",[index row],[index section]];
if ([index row]%2==0) {
self.switch1.on=YES;
}else {
self.switch1.on=NO;
}
}
- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation {
return YES;
}
- (voID)dIDReceiveMemoryWarning {
[super dIDReceiveMemoryWarning];
}
- (voID)vIEwDIDUnload {
[super vIEwDIDUnload];
self.lable=nil;
self.switch1=nil;
}
- (voID)dealloc {
[self.lable release];
[self.switch1 release];
[super dealloc];
}
@end
2.修改相应的xib文件:
添加相应的控件,并且相应的组建和相应的事件相关联。
最后我们实现RootVIEwController:
首先修改相应的文件:.h文件如下:
#import <UIKit/UIKit.h>
@class DetailVIEwController;
@interface RootVIEwController : UItableVIEwController {IBOutlet DetailVIEwController *detailVIEwController;
}
@property (nonatomic,retain) DetailVIEwController *detailVIEwController;
@end
.m文件如下:
- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw {
// Return the number of sections.
return 2;
}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 7;
}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static Nsstring *CellIDentifIEr = @"Cell";
UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];
if (cell == nil) {
cell = [[[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr] autorelease];
}
// Configure the cell…
cell.textLabel.text=[Nsstring stringWithFormat:@"ROW %d section %d",[indexPath row],[indexPath section]];
return cell;
}- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another vIEw controller.
// DetailVIEwController *detailVIEwController = [[DetailVIEwController alloc] initWithNibname:@"DetailVIEwController" bundle:nil];
// [self.navigationController pushVIEwController:detailVIEwController animated:YES];
// [detailVIEwController release];
[detailVIEwController deetail:indexPath];
}
2、修改相应的xib文件:
相应的事件和控件相联系。
运行结果如下:
总结
以上是内存溢出为你收集整理的iPad 用xib如何创建UISplitViewController应用程序全部内容,希望文章能够帮你解决iPad 用xib如何创建UISplitViewController应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)