开发者

how to trigger function in view from viewcontroller viewdidload method - objective c - iphone

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 开发者_如何学JAVAif 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.


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜