IOS開發之——使用Segue在StoryBoard之間切換

來源:互聯網
上載者:User

使用Segue可以在ViewController之間來回切換,下面就來說下切換方法:

1. 使用點擊按鈕進行切換

直接,在需要切換的View屬性介面,點擊Modal然後拉到前一個view介面或者是Button上



2. 手動進行跳轉

如果拉到了Button的TouchUpInside上,那麼點擊左側按鈕的時候就會切到右邊的View,如果拉到了view上,就會串連Manual,在代碼中實現跳轉


設定Segue的Indentifier屬性:


代碼中手動進行跳轉:

//在viewDidAppear裡面添加觸發segue進行自動跳轉-(void)viewDidAppear:(BOOL)animated{    [self performSegueWithIdentifier:@"drawecg" sender:self];}

註:在ViewDidLoad實現跳轉無效


3. 如何跳轉到任意一個頁面

在有可能進行上級跳轉的ViewController檔案中加上下面代碼,函數名稱任起:

#pragma mark 定義這個函數,別的ViewController在Exit的時候就能直接跳到這了- (IBAction)goHome:(UIStoryboardSegue *)segue{    [[segue sourceViewController] class];}

在想要跳轉view的Exit上右鍵,選擇這個goHome函數,拉到想要執行的按鈕上,就可以實現跳轉了


也可代碼實現返回上一個頁面,登出當前頁面:

-(void)lastPage{    NSLog(@"點擊了上一個視圖按鈕");    [self dismissViewControllerAnimated:YES completion:^(void){                // Code            }];}


也可這樣實現:

 // 擷取故事板 UIStoryboard *board = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; // 擷取故事板中某個View     UIViewController *next = [board instantiateViewControllerWithIdentifier:@"Second"]; // 跳轉     [self presentModalViewController:next animated:YES];


當然,如果你使用Navigation Controller,使用Push進行串連,就不是上面的代碼進行跳轉了:

跳轉到LandscapeViewController

//開啟一個橫屏介面- (IBAction)openLandscapeControl:(id)sender {    LandscapeViewController *control = [[LandscapeViewController alloc]initWithNibName:@"LandscapeViewController" bundle:nil];        [self.navigationController pushViewController:control animated:YES];}
使用pop返回上一個View
//返回前一頁- (IBAction)clickBack:(id)sender {    [self.navigationController popToRootViewControllerAnimated:YES];}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.