iPad 如何创建UISplitViewController应用程序
原文摘自:UISplitViewController的使用。
?
UISplitViewController在ipad中的使用
ipad的屏幕比iphone大,所以在界面上,ipad比iphone多一個(gè)UISplitViewController,用來(lái)實(shí)現(xiàn)ipad在橫屏?xí)r,分兩欄顯示所需要的界面,可以一邊是目錄一邊是具體的內(nèi)容。下面我將詳細(xì)的闡述UISplitViewController在ipad中的使用。
首先是創(chuàng)建一個(gè)工程:ipad.demo.
然后創(chuàng)建一個(gè)DetailViewController和RootViewController,其中RootViewController繼承UITableViewController。同事創(chuàng)建兩個(gè)相應(yīng)的xib文件。刪除ipad_demoViewController.相應(yīng)的類列表如下:
?
然后修改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中的控件和相應(yīng)的事件相聯(lián)系:連接過(guò)程是按住control鍵,然后點(diǎn)擊ipad_demo App Delegate,連接到Split View Controller,然后選擇自定義的事件即可,最后的結(jié)果如下:
最后在把相應(yīng)的容器換成自定義的容器:實(shí)現(xiàn)的方法是
最后的結(jié)果是:
現(xiàn)在我們?cè)趯?shí)現(xiàn)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.修改相應(yīng)的xib文件:
添加相應(yīng)的控件,并且相應(yīng)的組建和相應(yīng)的事件相關(guān)聯(lián)。
最后我們實(shí)現(xiàn)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、修改相應(yīng)的xib文件:
相應(yīng)的事件和控件相聯(lián)系。
運(yùn)行結(jié)果如下:
總結(jié)
以上是生活随笔為你收集整理的iPad 如何创建UISplitViewController应用程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 证监会:《证券期货业信息安全保障管理办法
- 下一篇: HTTP协议中返回代码302的情况