0

I'm currently making the initial menu view controller, which sets up the setting for main game view controller..

so in my menu game controller, I have

#import "MainGameViewController.h"
@implementation menuViewcontroller

 ......

-(void)setting{
NSMutableDictionary *regions =
[(MainGaimViewController *)self.delegate regions];
NSNumber *yesBool = [NSNumber numberWithBool:YES];
NSNumber *noBool = [NSNumber numberWithBool:NO];
[regions setValue:yesBool forKey:@"KM"];
[regions setValue:noBool forKey:@"KF"];
}

but this gives me the "Request for member 'delegate' in something not a structure or union

regions is a NSMutableDictionary in main game view controller. so I think menuViewController is not being able to access the function/variable in main game view controller despite the import. currently, I haven't declared "class MainGameViewController" in my menu implementation file. Could that be why? should I make an object of maingameviewcontroller and use it?

What could be wrong? Please help me out..

CosmicRabbitMediaInc
  • 1,165
  • 4
  • 21
  • 32

1 Answers1

1

I find it is much cleaner and clearer to put application-global data in separate singleton classes rather than wedge them in to the application delegate object and to try passing around pointers to root-level view controllers. View Controllers should focus just on the job of managing its view and responding to actions, and interacting with data models through the view. The data models themselves and app global data generally should sit outside of ViewControllers. The singleton pattern works nicely for data management, as the data is easily available to any piece of code in the app that needs it without having to worry about setting up delegate protocols, or whether a view controller owning data is valid any more.

You can see my answer to this question for how to set up a singleton data manager class:

Objective C: store variables accessible in all views

Community
  • 1
  • 1
Bogatyr
  • 19,255
  • 7
  • 59
  • 72