Maintain variables across multiple Views

Posts: 6
Joined: 2008.11
Post: #1
I need to use some variables in multiple views. I have different .m files for different Views.

I kept the variables in AppDelegate that will be used in different Views. Whenever I need any of them I create a pointer to AppDelegate using sharedApplication method, and access that variable through the AppDelegate pointer (using dot (.) operator). Is it fair? Or there is a better approach? If there is a better approach, please describe it. Is my approach creating any cyclic reference (Since, AppDelegate has a pointer to a View object which is creating pointer to AppDelegate to access to another View instance)? Let me give an example,

#import "View1.h"
#import "View2.h"

@interface AppDelegate : NSObject <UIApplicationDelegate>{
View1* v1;
View2* v2;

#import "AppDelegate.h"
-(void) someMethod{
AppDelegate *appDel = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[appDel.v1 someMethodOfView1];
Quote this message in a reply
Posts: 8
Joined: 2008.09
Post: #2
Maybe this post can help you out:


Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Multiple XIB or Views Jerm #1 1 4,661 Feb 2, 2010 02:10 AM
Last Post: Newbrof
  Messaging between separate views Toontingy 0 3,020 Jan 9, 2010 05:10 PM
Last Post: Toontingy
  OpenGL ES 2d game - multiple EAGL Views or not? Elphaba 4 6,721 Aug 4, 2009 10:42 AM
Last Post: maximile
  views and OpenGL jeffro 0 2,830 Jan 20, 2009 11:18 PM
Last Post: jeffro
  Multiple OpenGL views tfifriday 2 4,888 Dec 28, 2008 02:51 PM
Last Post: tfifriday