按下按钮时,应用程序在iPhone模拟器中崩溃。 Xcode 3.2.5

时间:2011-06-14 23:25:59

标签: iphone xcode ios-simulator

我的应用是标签栏应用。底部有两个标签,第一个标签上有一个插座,带有一个通向新窗口的按钮。当我在xcode中构建代码时,它会成功。当我在模拟器中启动应用程序并单击通向新窗口的按钮时,它会使应用程序崩溃。这是我的“FirstViewController”和“GuitarBrandsViewController”

的代码

FirstViewController.h -

#import <UIKit/UIKit.h>
#import "GuitarBrandsViewController.h"


@interface FirstViewController : UIViewController {
    FirstViewController *firstViewController;

    IBOutlet UIWindow *window;
    IBOutlet UIWindow *GuitarBrands;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

-(IBAction)gotoGuitarBrands;

@end

FirstViewController.m

#import "FirstViewController.h"


@implementation FirstViewController
@synthesize window;

-(IBAction)gotoGuitarBrands{

    GuitarBrandsViewController *screen = [[GuitarBrandsViewController alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:screen animated:YES];
    [screen release];
}

GuitarBrandsViewController.h

#import <UIKit/UIKit.h>
#import "FirstViewController.h"

@interface GuitarBrandsViewController : UIViewController {
    GuitarBrandsViewController *guitarBrandsViewController;
    IBOutlet UIWindow *window;
    IBOutlet UIWindow *Main;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
-(IBAction)gotoMain;

@end

GuitarBrandsViewController.m

#import "GuitarBrandsViewController.h"

@implementation GuitarBrandsViewController
@synthesize window;

-(IBAction)gotoMain{

    FirstViewController *screen = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:screen animated:YES];
    [screen release];
}

1 个答案:

答案 0 :(得分:1)

我假设您正在使用Interface Builder创建GuitarBrandsViewController,因为类中的代码本身不能自行运行。

但是,当您初始化GuitarBrandsViewController时,您不会传递NIB,因此您在没有来自IB的实际NIB信息的情况下分配控制类。

而不是

 GuitarBrandsViewController *screen = [[GuitarBrandsViewController alloc] initWithNibName:nil bundle:nil];

使用

GuitarBrandsViewController *screen = [[GuitarBrandsViewController alloc] initWithNibName:@"GuitarBrandsViewController.xib" bundle:nil];

将笔尖名称调整为您使用的实际笔尖的名称。