Storyboard - Workflow for a corner-based game

I am creating a turn-based game and would like to know the right process for my workflow. I currently have the following:

Home View controller (which has UITableView)
Click on a line from section 1> Download a UINavigationControllerusing path 1
Click on a line from section 2> Download a UINavigationControllerusing path 2

As an example:
path 1 - play turn
2; guess your move

Each path has about 4-5 UIViewControllersloaded into the navigation controller.

Now I am at the stage when one path 2 is completed, the user must also play a turn (i.e. go through path 2, then path 1).

What is the correct way to do this? should I create a segue from the last controller in path 2> leading to path 1. The problem is that in path 2 there is UIViewControllerone that has UIImageViewa large image and it will freeze in memory. Ideally, it is cleared as such before the user starts path 1 (after completion of path 2).

+4
source share
4 answers

, , . ViewController Path2. UINavigationController. , .

- (IBAction)completeButtonPressed:(id)sender {
    NSLog(@"complete button pressed");

    Path2ViewController *path2StartVC = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"Path21VC"];

    [self.navigationController setViewControllers:[NSArray arrayWithObject:path2StartVC] animated:YES];

}

github .

0

popToRootViewControllerAnimated, , movetopath2. NSUserDefaults , .

[self.navigationController popToRootViewControllerAnimated:YES];

, :

Your work flow

ViewController.m

 #pragma mark - UITableViewDelegate
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

if (indexPath.section == 0)
{

    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

    PathOneViewController *pathController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"PathOneViewController"];

    [self.navigationController pushViewController:pathController animated:YES];

}
else
{
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

    PathTwoViewController *pathController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"PathTwoViewController"];

    [self.navigationController pushViewController:pathController animated:YES];

}
}

PathOneDetailViewController.m

 - (IBAction)actionMoveToPathTwo:(id)sender { // Move to path two

AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];

UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"PathTwoViewController"];

UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
appDelegateTemp.window.rootViewController = navigation;
}

- (IBAction)actionMoveToHome:(id)sender { // Move to table View

AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];

UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ViewController"];

UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
appDelegateTemp.window.rootViewController = navigation;
}

PathTwoDetailViewController.m

- (IBAction)actionMoveToHome:(id)sender { // Move to table View


AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];

UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ViewController"];

UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
appDelegateTemp.window.rootViewController = navigation;


}

- (IBAction)actionMoveToPath1:(id)sender { // Move to path one


AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];

UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"PathOneViewController"];

UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
appDelegateTemp.window.rootViewController = navigation;

}
+2
  • 2

  • Home View Controller

  • Home View Controller popToRootViewControllerAnimated:.

  • segue 1.

0

UINavigationController "Home View Controller" (UITableView). . , , UINavigation .

, popToRootViewControllerAnimated:. " ". , popToRootViewControllerAnimated: , . , .

, . , UINavigationController , . , , . , prepareForSegue: : .

, UIImageView . . , UIImageView. , , - . , . . segue . .

. , .

0
source

Source: https://habr.com/ru/post/1524384/