【发布时间】:2010-01-15 07:48:16
【问题描述】:
我正在尝试在我的应用中使用 2 个视图,在我的主屏幕上使用 2 个按钮。对于这些按钮中的每一个,我都创建了一个新类并将以下代码添加到我的视图控制器中:
ViewController.h:
#import <UIKit/UIKit.h>
@interface Gallerie2ViewController : UIViewController {
}
- (IBAction)switch2class1:(id)sender; // 1st button
- (IBAction)switch2class2:(id)sender; // 2nd one
@end
ViewController.m:
#import "ViewController.h"
#import "class1.h"
#import "class2.h"
@implementation ViewController
- (IBAction)switch2class1:(id)sender
{
Class1 *Class1view = [[Class1 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Class1view animated:YES];
}
- (IBAction)switch2class2:(id)sender
{
Class2 *Class2View = [[Class2 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Class2View animated:YES];
}
Class1.h/.m 与 Class2.h/.m 具有相同的内容,但是在运行我的应用程序时,第一个按钮工作正常(打开 Class1 视图)但第二个按钮使应用程序崩溃!
我做错了什么?
【问题讨论】:
-
日志说什么?在xcode中,运行->控制台,然后点击清除控制台,然后构建运行,崩溃后将代码粘贴到这里
-
一个与崩溃无关的小问题:看起来 Class1 和 Class2 是 UIViewController 的子类,所以如果它读取“UIViewController* controller = ...”而不是“Class2 *Class2View = ...”