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
          在沒有安裝顯卡驅動的雪豹下開發真是痛苦!
          悲劇的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!!!

          主站蜘蛛池模板: 棋牌| 平乡县| 海淀区| 阿拉善右旗| 巧家县| 金堂县| 湘西| 准格尔旗| 梁山县| 股票| 忻城县| 通渭县| 湾仔区| 康乐县| 巫山县| 廉江市| 肇庆市| 柯坪县| 读书| 察隅县| 吉首市| 光泽县| 沙湾县| 南澳县| 永吉县| 泽州县| 德庆县| 台安县| 威远县| 徐州市| 揭阳市| 宽城| 固始县| 呼伦贝尔市| 高要市| 西贡区| 灵丘县| 康平县| 林口县| 杨浦区| 宁德市|