0

I want to keep track of when I move from one view to another.

So I created a global bool to keep track of this.

This works, but is it the best practice? Should I make it a property?

Thanks!

bool didNavigateToFullWebView; 

    viewDidAppear: (BOOL) animated {
     if(didNavigateToFullWebView) {
          //Load differently depending on the last view visited.
      } 
    }

    - (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath {  
     didNavigateToFullWebView = YES; 
 }
itgiawa
  • 1,616
  • 4
  • 16
  • 28
  • if you're using a navigation controller, you'll have a "stack" of previous view controllers (in a `viewControllers` array property) to fall back upon. – Michael Dautermann Apr 22 '12 at 01:26

1 Answers1

1

A common practice is to put all your state in your model class (as in "model - view - controller" pattern), and make your model a singleton. Then all globals go into the model class as properties, or become hidden behind publicly available methods. This is better than scattered globals, because the readers of your code will need to look in a single place for all the state information of your application. Here is a stack overflow question with a relevant discussion.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523