2010-01-15 74 views
0

我想在我的应用程序中使用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个按钮会使应用程序崩溃!

我在做什么错?

+1

日志说什么?在xcode中,运行 - >控制台,然后单击清除控制台,然后构建并运行,并在代码崩溃后将代码粘贴到此处 – 2010-01-15 07:58:29

+0

与崩溃无关的次要nitpick:它看起来像Class1和Class2是UIViewController的子类,所以它会如果它读取“UIViewController * controller = ...”,而不是“Class2 * Class2View = ...”,则不会引起混淆。 – Costique 2010-01-15 08:13:58

回答

0

好吧,我已经检查了控制台(感谢Sam Jarman),发现了这个问题的原因:我的一个类(Class2)被命名为List。所以它使用List.h和List.m编译,但List.h已经定义(可能是SDK的一部分)。它没有在编译时发生任何错误/警告冲突,但是..我已经将list.h重命名为cat.h,它现在可以正常工作!

谢谢!

+1

很高兴您很快解决了问题。继续并将其标记为接受的答案。除了你会获得额外的声誉,它有助于社区和网站:) – Anurag 2010-01-15 08:46:03