Maintain variables across multiple Views
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
View2.cpp
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];
}
Maybe this post can help you out:
http://iphonedevelopertips.com/objective...ables.html
Cheers,
Pierre
http://iphonedevelopertips.com/objective...ables.html
Cheers,
Pierre
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Multiple XIB or Views | Jerm #1 | 1 | 3,151 |
Feb 2, 2010 02:10 AM Last Post: Newbrof |
|
| Messaging between separate views | Toontingy | 0 | 1,786 |
Jan 9, 2010 05:10 PM Last Post: Toontingy |
|
| OpenGL ES 2d game - multiple EAGL Views or not? | Elphaba | 4 | 4,290 |
Aug 4, 2009 10:42 AM Last Post: maximile |
|
| views and OpenGL | jeffro | 0 | 1,772 |
Jan 20, 2009 11:18 PM Last Post: jeffro |
|
| Multiple OpenGL views | tfifriday | 2 | 3,121 |
Dec 28, 2008 02:51 PM Last Post: tfifriday |
|

