我想在我的应用程序中使用2个按钮,在我的主屏幕上显示2个视图。对于这些按钮的我已经创建了一个新的类,下面的代码添加到我的视图控制器:iPhone视图编程
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的内容相同,但是在运行我的应用程序时,第1个按钮可以正常工作(打开Class1视图),但第2个按钮会使应用程序崩溃!
我在做什么错?
日志说什么?在xcode中,运行 - >控制台,然后单击清除控制台,然后构建并运行,并在代码崩溃后将代码粘贴到此处 – 2010-01-15 07:58:29
与崩溃无关的次要nitpick:它看起来像Class1和Class2是UIViewController的子类,所以它会如果它读取“UIViewController * controller = ...”,而不是“Class2 * Class2View = ...”,则不会引起混淆。 – Costique 2010-01-15 08:13:58