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 閱讀(988) 評論(0)  編輯  收藏 所屬分類: Iphone Development
          在沒有安裝顯卡驅(qū)動的雪豹下開發(fā)真是痛苦!
          悲劇的thinkpad。。。所以不能截圖。。。稀爛!
          1. 創(chuàng)建一個viewcontroller,比如SettingViewController,同時創(chuàng)建實(shí)現(xiàn)文件和頭文件,不多說
          2. 創(chuàng)建該viewcontroller對應(yīng)的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文件中添加具體實(shí)現(xiàn)代碼,如下:

          @implementation SettingViewController

          @synthesize isPushedView;

          - (void)viewDidLoad {

              [super viewDidLoad];

              if(isPushedView == NO) {

                  self.navigationItem.title = @"設(shè)置";

                  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文件中添加實(shí)現(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!!!

          主站蜘蛛池模板: 宾阳县| 武清区| 洞头县| 错那县| 安乡县| 仪陇县| 卢湾区| 邛崃市| 巴彦县| 鄂州市| 綦江县| 宁海县| 揭阳市| 米泉市| 青阳县| 鹰潭市| 东安县| 重庆市| 留坝县| 独山县| 长顺县| 宜君县| 榆中县| 重庆市| 内江市| 广饶县| 鸡东县| 大港区| 松潘县| 五河县| 鄂尔多斯市| 磴口县| 陈巴尔虎旗| 拉萨市| 台安县| 万州区| 开鲁县| 金寨县| 东兰县| 萨嘎县| 融水|