参考までに、私はobjective-Cでプログラミングしていますが、誰でも助けてくれるかもしれません。私は過去 2 時間ここに座って何が問題なのかを突き止めようとしており、この単純で小さなコーディングの問題をデバッグするために知っていることはすべて実行しました。以下のコードをチェックしてください。説明します。アプリケーションでは、MainScreenViewController から始まります。私のアプリケーションは、ユーザーに 2 つの選択肢を与えます...「マスター」ボタンまたは「ワーカー」ボタン (基本的なクライアント/サーバー モデル) を選択します。ユーザーの選択に基づいて、アプリケーションは別のビュー (MasterViewController または WorkerViewController) をロードすることになっています。ここで、アプリケーションを実行すると、印刷コマンドに従って「マスター」ボタンを選択した場合、私のプログラムでは、「masterButtonPressed - Stage 1」と「」が出力されます。間違った?私が言ったように、「マスター」ボタンを押してもビューは変わりません。ご協力いただきありがとうございます!
MainScreenViewController.h
@interface MainScreenViewController : UIViewController {
}
-(IBAction)masterButtonPressed;
-(IBAction)workerButtonPressed;
@end
MainScreenViewController.m
@implementation MainScreenViewController
-(IBAction)masterButtonPressed {
NSLog(@"masterButtonPressed - Stage 1");
[ErwinAppDelegate changeToMaster];
NSLog(@"masterButtonPressed - Stage 2");
}
-(IBAction)workerButtonPressed {
NSLog(@"workerButtonPressed - Stage 1");
[ErwinAppDelegate changeToWorker];
NSLog(@"workerButtonPressed - Stage 2");
}
@end
ErwinAppDelegate.h
@class MainScreenViewController, MasterViewController, WorkerViewController;
@interface ErwinAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainScreenViewController *mainScreenViewController;
MasterViewController *masterViewController;
WorkerViewController *workerViewController;
}
@property(nonatomic, retain) IBOutlet UIWindow *window;
@property(nonatomic, retain) IBOutlet MainScreenViewController *mainScreenViewController;
@property(nonatomic, retain) IBOutlet MasterViewController *masterViewController;
@property(nonatomic, retain) IBOutlet WorkerViewController *workerViewController;
-(void)changeToMaster;
-(void)changeToWorker;
@end
ErwinAppDelegate.m
@implementation ErwinAppDelegate
@synthesize window, mainScreenViewController, masterViewController, workerViewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window addSubview:mainScreenViewController.view];
[window addSubview:masterViewController.view];
[window addSubview:workerViewController.view];
[window makeKeyAndVisible];
// Bring first view up front
[window bringSubviewToFront:mainScreenViewController.view];
}
-(void)changeToMaster {
NSLog(@"changeToMaster - Stage 1");
[window bringSubviewToFront:masterViewController.view];
NSLog(@"changeToMaster - Stage 2");
}
-(void)changeToWorker {
NSLog(@"changeToWorker - Stage 1");
[window bringSubviewToFront:workerViewController.view];
NSLog(@"changeToWorker - Stage 2");
}
@end