开发者

App crashes in iPhone simulator when button is pressed. Xcode 3.2.5

开发者 https://www.devze.com 2023-03-13 05:22 出处:网络
My app is a tab bar application. There are two tabs at the bottom and an outlet on the first tab with a button that leads to a new window. When I build the code in xcode, it succeeds. When I launch th

My app is a tab bar application. There are two tabs at the bottom and an outlet on the first tab with a button that leads to a new window. When I build the code in xcode, it succeeds. When I launch the app in the simulator and click the button leading to the new window, it crashes the app. This is my code for the "FirstViewController" and the "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 *guitarBrandsVie开发者_Python百科wController;
    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];
}


I assume you are creating the GuitarBrandsViewController using Interface Builder as the code in the class itself would not work on it's own.

However, when you initialize GuitarBrandsViewController, you don't pass the NIB so you allocate the Controlling Class without the actual NIB information from IB.

Instead of

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

Use

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

Adjust the nib name to the name of the actual nib you use.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号