0

私は初心者のiOS開発者であり、ログインページにビューを追加する方法について質問がありました。現在、私はログインページを持っており、ログインページが表示される前に、別のモーダルビューを実行して、ユーザーが最初に閉じる必要があることを確認する必要があります。これをxcodeに追加するにはどうすればよいですか?

4

1 に答える 1

1

ビューコントローラを表示するためのいくつかのオプションがあります。

- (IBAction)goToLoginView:(id)sender
{
     //if you are using xibs use this line
     UIViewController *controller = [[UIViewController alloc] initWithNibName:@"myXib" bundle:[NSBundle mainBundle]];
     //if you are using storyboards use this line
     UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"myViewControllersID"];

     //to present the controller modally use this
     [self presentViewController:controller animated:YES completion:nil];
     //or if you are pushing to this controller using a navigation controller use this
     [self.navigationController pushViewController:controller animated:YES];
}

次に、View Controllerを閉じるには、次を使用します。

- (IBAction)closeMyController
{
    //if the view was presented modally close it with this
    [self dismissViewControllerAnimated:YES completion:nil];

    //and to pop back up the navigation stack
    [self.navigationController popToRootViewControllerAnimated:YES];
}
于 2012-09-07T17:25:59.907 に答える