私は一日中これに頭を悩ませてきました。単純なことのように思えますが、理解できません。
XCode の「View-based Application」テンプレートを使用して作成した iOS アプリがあります。これが本質的に私が持っているコードです:
AppDelegate.h:
#import <UIKit/UIKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MainViewController *viewController;
@end
AppDelegate.m:
#import "AppDelegate.h"
#import "MainViewController.h"
@implementation AppDelegate
@synthesize window, viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
MainViewController.h:
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController {
}
-(IBAction) button:(id)sender;
@end
MainViewController.m:
#import "MainViewController.h"
#import "ModalViewController.h"
@implementation MainViewController
...
-(IBAction) button:(id)sender {
ModalViewController *mvc = [[[ModalViewController alloc] initWithNibName:NSStringFromClass([ModalViewController class]) bundle:nil] autorelease];
[self presentModalViewController:mvc animated:YES];
}
@end
ModalViewController には特に意味はありません。
したがって、ボタンが押されたときにモーダル ビューが表示されます。ボタンを押すと、1 秒間ハングした後、クラッシュしてホーム画面に戻り、エラー メッセージは表示されません。
私は困惑しています、私が間違っていることを教えてください!