GameScreen.m ファイルに次のメソッドがあり、独自の宣言があります - (void) GameScreen.h ファイルの 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];
}
これは、GameScreenViewController.m が viewController で、GameScreen クラスがすべてのボタン クリックやタイマーの実行などを取得するイベント ハンドラーである GameScreen.xib ファイルのボタンのタイトルを変更することになっています。 ] から [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]];
}