views:

262

answers:

1

Hi everyone,

I'm trying to trigger a function in a view class, from the view controller once it has finished loading.

Currently the code I'm trying to run is this

GameView *gameView = (GameView *)[[UIView sharedApplication] delegate]; 
[gameView loadText];

I've borrowed this code from other code which triggers functions on the appdelegate class.

I'm also not sure how to get a more detailed error message than objc_exception_throw, so if anyone could tell me how to debug it further that would be great.

This code is running inside the GameViewController.m file, which does import GameView.h

The warning xcode states is

warning : 'UIView' may not respond to '+sharedApplication' Messages witjhout a matching method signature will be assumed to return 'id' and accept '...' as arguments.)

Thanks for any help. Let me know if I have to post more code.

+2  A: 

Try this

GameView *gameView = (GameView *)[[UIApplication sharedApplication] delegate];
[gameView loadText];

Sam

PS However, the delegate method of UIApplication will give you an app delegate which I would expect to be named something like GameAppDelegate - you are casting to a class called GameView, which I assume inherits from UIView - this is almost 100% not what you are expecting to do?

EDIT:

If the gameView is the view associated with this view controller, this should work :

GameView *gameView = (GameView *)self.view;
[gameView loadText];
deanWombourne
Yes your right, can you explain what I should be doing differently to get this to work, or some tutorial I can follow that will teach me this. thanks.
optician
See my edit above but if that's doesn't work, add another comment with more details :)
deanWombourne