Maintain variables across multiple Views

Apprentice
Posts: 6
Joined: 2008.11
Post: #1
Hello,
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,

AppDelegate.h
Code:
#import "View1.h"
#import "View2.h"

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

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

http://iphonedevelopertips.com/objective...ables.html

Cheers,

Pierre
Quote this message in a reply
Post Reply 

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