GameScreen.mファイルで、GameScreen.hファイルに独自の宣言 - (void)drawNumbersを持つ以下のメソッドがあります:
//GameScreen.h
#import
@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.xibファイル内のボタンのタイトルを変更するはずです。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
@class myAppViewController, GameScreenViewController;
@interface myAppDelegate : NSObject
{
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]];
}