1

I have a screen in which a user can choose a set of meals - once the meals have been chosen the application fetches results form a database and displays a list of them. Now, I would like to implement a condition to decide whether the next screen should be loaded or not - ie. if there's no internet connection then show an alert and don't display the next screen etc.

I've implemented a system to check whether there is an internet connection or not but I'm not sure how and where to decide of the next screen should be loaded. Any ideas?

Thanks,

KerrM
  • 5,139
  • 3
  • 35
  • 60

4 Answers4

1

1.5 other options: If you're willing to split stories and nibs, just load up a nib when you want/need to. If you want to stick to stories exclusively, just load up another story when you need to. Same thing as loading a nib:

UIStoryboard *otherStoryboard = [UIStoryboard storyboardWithName:@"OtherStory" bundle:nil];
UIViewController *otherController = [otherStoryboard instantiateInitialViewController];
[self.navigationController pushViewController: otherController animated:YES];
kwerle
  • 2,225
  • 22
  • 25
0

Once you know in your code whether you want to display the next screen or not, can you not just add an if statement that either loads the next screen or displays a warning that there is no connection?

if (hasConnection) {
  // Show next screen
} else {
  // Show warning
}
aaroncatlin
  • 3,203
  • 1
  • 16
  • 27
  • Yes that's what I'm doing but I'm not sure where to put that code in xcode 4.2 - using storyboards. – KerrM Mar 06 '12 at 14:23
0

You supposedly have an action that is being fired when the user selects some meals, haven't you? In this action you'd call [UINavigationController pushViewController:nextViewController animated:YES] or something like this. Put this function call into the condition of your preference, and show a popup otherwise.

MrTJ
  • 13,064
  • 4
  • 41
  • 63
  • I'm using storyboards, so I don't have that code, I've got a prepareForSegue method though. – KerrM Mar 06 '12 at 14:22
  • Then you might have a look at on this: http://stackoverflow.com/questions/7819796/how-to-cancel-a-uistoryboardsegue – MrTJ Mar 06 '12 at 14:40
0

I solved this issue using the answers from: Prevent segue in prepareForSegue method? by linking the segue to my main view controller, then attaching an IBAction to the button that was originally the segue initiator and performing the logic in that method. If it all cleared then I call [self performSegueWithIdentifier:@"results" sender:self];

Community
  • 1
  • 1
KerrM
  • 5,139
  • 3
  • 35
  • 60