Neil的备忘录

just do it
posts - 66, comments - 8, trackbacks - 0, articles - 0

Iphone 带NavigationBar的ModalView

Posted on 2010-10-06 18:16 Neil's NoteBook 阅读(859) 评论(0)  编辑  收藏 所属分类: Iphone Development
在没有安装显卡驱动的雪豹下开发真是痛苦!
悲剧的thinkpad。。。所以不能截图。。。稀烂!
1. 创建一个viewcontroller,比如SettingViewController,同时创建实现文件和头文件,不多说
2. 创建该viewcontroller对应的view文件,比如SettingView.xib,没什么好说的
3. 双击刚才创建的xib文件,指定class为第一步创建的viewcontroller,在interface builder中将view和file owner连接起来
4. 在创建的SettingViewController.h文件中定义一个bool类型的变量,该变量用来指示modal view是否已弹出,代码如下:

@interface SettingViewController : UIViewController {

BOOL isPushedView;

}

@property (nonatomic, readwrite) BOOL isPushedView;

5. 在SettingViewController.m文件中添加具体实现代码,如下:

@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文件中添加实现代码,如下:

- (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!!!


只有注册用户登录后才能发表评论。


网站导航: