標籤:style http io os ar for 檔案 div sp
iOS開發 跳轉情境的三種方式2012年10月17日, 15:32
假設A跳轉到B,三種方法:
1.按住ctrl鍵,拖動A上的控制項(比如說UIButton)到B上,快顯功能表,選擇Modal.不需要寫任何代碼,在A上點擊Button就會跳轉到B
2. 按住ctrl鍵,拖動A上的View Controller到B上,快顯功能表,選擇Modal,兩個情境間自動添加連接線和表徵圖,選中該表徵圖,開啟Storyboard Segue,identifier輸入一個標識符,這裡以”aaaa”為例.A裡需要跳轉時,執行下面的代碼:
1 |
[self performSegueWithIdentifier:@"aaaa" sender:self]; |
3.完全用代碼來實現,代碼如下:
123456789 |
//先擷取UIStoryBoard對象,參數為檔案名稱 UIStoryboard *mainStoryBoard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; //擷取SecondViewController執行個體,參數是StoryBoard ID,選中View Controller,在Identity Inspector中 SecondViewController *second=[mainStoryBoard instantiateViewControllerWithIdentifier:@"second"]; //設定過渡的樣式,和顯示的樣式 second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; second.modalPresentationStyle=UIModalPresentationFormSheet; //顯示 [self presentViewController:second animated:YES completion:nil]; |
iOS開發 跳轉情境的三種方式