我在 GameScreen.m 文件上有以下方法,在 GameScreen.h 文件上有自己的声明 - (void) drawNumbers:
//GameScreen.h
#import <UIKit/UIKit.h>
@interface GameScreen : UIView
{
IBOutlet UIButton *cell00;
}
- (void) drawNumbers;
- (IBAction) onCellClick:(id)sender;
@property (nonatomic, retain) IBOutlet UIButton *cell00;
@end
//GameScreen.m
#import "GameScreen.h"
- (void) drawNumbers
{
//testing if this works, so far it doesn't
[cell00 setTitle:@"Whatever" forState:UIControlStateNormal];
[cell00 setTitle:@"Whatever" forState:UIControlStateHighlighted];
}
我试图从我的 GameScreenViewController.m 文件中调用这个方法,这样:
//GameScreenViewController.m
#import "GameScreenViewController.h"
#import "GameScreen.h"
...
- (void) viewDidLoad
{
GameScreen *aGameScreen = [[GameScreen alloc] init];
[aGameScreen drawNumbers];
[aGameScreen release];
[super viewDidLoad];
}
这应该更改 GameScreen.xib 文件中按钮的标题,其中 GameScreenViewController.m 是 viewController,GameScreen 类是事件处理程序,我在其中获得所有按钮点击、计时器运行等。我正在尝试调用 [drawNumbers ] 来自 [viewDidLoad],因为我希望在屏幕显示在前面时更改标题(屏幕管理是通过 AppDelegate 文件完成的)。
问题是,如果我从同一个类中调用 drawNumbers 实例
//GameScreen.m
#import GameScreen.h
-(void) onButtonClick:(id)sender
{
//some other code
[self drawNumbers];
}
它可以工作(也就是说,代码实现或图形界面没有错)。
我浏览过 Apple Guide 和互联网上的大量页面,但我似乎找不到任何线索。任何进一步的帮助(包括关于在 ADG 中确切找到答案的答案)将不胜感激。
(编辑:这里是 AppDelegate 代码翻转到特定视图,以防万一):
//myAppAppDelegate.h
#import <UIKit/UIKit.h>
@class myAppViewController, GameScreenViewController;
@interface myAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
myAppViewController *viewController;
GameScreenViewController *gameScreenViewController;
}
- (void) flipToGameScreen;
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) GameScreenViewController *gameScreenViewController;
@end
//myAppAppDelegate.m
-(void) flipToGameScreen
{
GameScreenViewController *aGameScreenView = [[GameScreenViewController alloc] initWithNibName: @"GameScreen" bundle:nil];
[self setGameScreenViewController:aGameScreenView];
[aGameScreenView release];
[gameScreenViewController.view.frame = [[UIScreen mainScreen] applicationFrame];
[viewController.view removeFromSuperview];
[self.window addSubview:[gameScreenViewController view]];
}