在沒有安裝顯卡驅動的雪豹下開發(fā)真是痛苦!
悲劇的thinkpad。。。所以不能截圖。。。稀爛!
1. 創(chuàng)建一個viewcontroller,比如SettingViewController,同時創(chuàng)建實現(xiàn)文件和頭文件,不多說
2. 創(chuàng)建該viewcontroller對應的view文件,比如SettingView.xib,沒什么好說的
3. 雙擊剛才創(chuàng)建的xib文件,指定class為第一步創(chuàng)建的viewcontroller,在interface builder中將view和file owner連接起來
4. 在創(chuàng)建的SettingViewController.h文件中定義一個bool類型的變量,該變量用來指示modal view是否已彈出,代碼如下:
@interface SettingViewController : UIViewController {
BOOL isPushedView;
}
@property (nonatomic, readwrite) BOOL isPushedView;
5. 在SettingViewController.m文件中添加具體實現(xiàn)代碼,如下:
@implementation SettingViewController
@synthesize isPushedView;
- (void)viewDidLoad {
[super viewDidLoad];
if(isPushedView == NO) {
self.navigationItem.title = @"設置";
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(cancel_Clicked:)] autorelease];
}
}
-(void) cancel_Clicked:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
6. 在RootViewController.h文件中定義變量,代碼如下:
@class SettingViewController;
@interface RootViewController : UITableViewController {
SettingViewController *settingViewController;
UINavigationController *settingNavController;
}
7. 在RootViewController.m文件中添加實現(xiàn)代碼,如下:
- (void) settingClicked {
if(settingViewController == nil) {
settingViewController = [[SettingViewController alloc] initWithNibName:@"SettingView" bundle:[NSBundle mainBundle]];
settingViewController.isPushedView = NO;
}
if(settingNavController == nil) {
settingNavController = [[UINavigationController alloc] initWithRootViewController:settingViewController];
[self.navigationController presentModalViewController:settingNavController animated:YES];
}
}
8. DONE!!!