簡體   English   中英

自動更改為下一個ViewController

[英]change automatically to next ViewController

以下情況。

在情節提要中,我有兩個ViewController。 ViewController_1ViewController_2 當第一個ViewController_1打開並且viewdidload void被加載時,如何在一定時間( 我可以調整 )之后自動移動到下一個ViewController_2 ,而無需任何用戶干預? 我正在為我的方法使用此自我呼喚:

    [self performSelector:@selector(toNewViewController:) withObject:nil 
afterDelay:timeInSeconds];

但是我不確定如何使用視圖控制器編寫方法以查看控制器轉換。 有任何想法嗎?

從第一個視圖到第二個視圖,在情節提要中創建序列(從一個視圖到另一個視圖的箭頭)。

然后,您需要調用toNewViewController方法:

[self performSegueWithIdentifier:@"nameOfYourSegue" sender:self];

此調用將執行從第一個視圖到第二個視圖的過渡。

首先,您必須創建一個函數,該函數將顯示您的第二個ViewController。

[NSTimer scheduledTimerWithTimeInterval:certainTime target:self selector:@selector(presentnextView) userInfo:nil repeats:NO];

-(void)presentnextView
{
    ViewController *secondView=[[ViewController alloc] init];
    [self presentViewController:secondView animated:YES completion:nil];
    [secondView release];
}

您可能還需要此方法來攔截控制器傳輸並設置目標視圖控制器:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
        if ([[segue identifier] isEqualToString:@"nameOfYourSegue"]) {
                /* In my case its navigation controller, for you it may be different */
                UINavigationController *navi = [segue destinationViewController];
                ComposeViewController *compose = [navi.viewControllers objectAtIndex:0];
                compose->delegate = self;
                compose.login = self.login;
                compose.name = self.name;
        }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM