0

我整天都在努力解决这个问题,这似乎很简单,但我无法弄清楚。

我有一个使用 XCode 中的“基于视图的应用程序”模板创建的 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

主视图控制器.h:

#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController {
}
-(IBAction) button:(id)sender;
@end

主视图控制器.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 没有什么有趣的地方。

因此,按下按钮时应显示模态视图。当我按下按钮时,它会挂起一秒钟然后崩溃回到主屏幕,没有错误消息。

我被难住了,请告诉我我做错了什么!

4

1 回答 1

0

ModalViewController 没有什么有趣的地方。

尽管可能没有任何有趣的东西,但仍然可能存在导致问题的原因。

您的视图控制器是否覆盖了函数 loadView?

如果你不调用 [super loadView]; 几次让我遇到的一个问题是 首先在您覆盖的 loadView 方法中。不这样做会在移动到该视图控制器时导致崩溃。

祝你好运尝试解决这个问题!

ñ

于 2010-12-28T10:04:05.133 回答