views:

45

answers:

1

Please bear with me, this is probably a very simple problem for an expert but I'm new to the language.

I'm trying to create an application that dynamically generates and releases a series of views, which are displayed in the main window. The problem I am having is in swapping between them. I want each view to contain buttons that cause the view to change. I can make a view close itself, but I don't know how to order the main program to change its own view to something new once that's been done (i.e. message the main application from within one of its child objects). I suppose I could make the main view of the application into a global, but I'd rather be able to contact the main application directly as this strikes me as being somewhat neater and less prone to other problems. Problem is, I don't know the main app's identifier. The convenient 'self' identifier gets used so often that I've never seen a code snippet that contains an identifier for the main application that could be called from outside it. It would also be useful to be able to link NIB file objects directly to attributes held in common by the main program.

Am I going about this in entirely the wrong way? Is there a generic 'main app' identifier? Is it possible to create one, if one isn't generated automatically?

-Ash

+2  A: 

Assuming that by 'main application' you mean your app delegate, you can get it using this method :

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
deanWombourne
This really isn't working, don't know why. There must be some simple way to message the app delegate from within a different view controller?
Ash
Did you include the app delegate file in the view controller you were trying to access it from? Did you access the object via `appDelegate.myObject` ? dean's method is correct
iWasRobbed
What do you mean by 'not working' - does it compile? Do you get an error when you run the app? Does it crash?
deanWombourne
Ahhahah, I think I see what's going wrong here! You see, in the past Objective languages I've studied, you don't declare the files for 'parent' objects in their children because it creates a circular reference. The language automatically fills in the gaps. I'm guessing that the problem is I'm not including the right files as iWasRobbed says. I guess I'd better find out how to do that. This is the problem when learning from tutorials and help-files; it's so difficult to find the precise information you want.
Ash