[英]App crashes in iPhone simulator when button is pressed. Xcode 3.2.5
我的应用程序是一个标签栏应用程序。 底部有两个选项卡,第一个选项卡上有一个插座,带有一个通向新 window 的按钮。 当我在 xcode 中构建代码时,它成功了。 当我在模拟器中启动应用程序并单击指向新 window 的按钮时,应用程序会崩溃。 这是我的“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
第一视图控制器.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];
}
我假设您正在使用 Interface Builder 创建 GuitarBrandsViewController,因为 class 本身的代码无法单独运行。
但是,当您初始化 GuitarBrandsViewController 时,您没有传递 NIB,因此您在没有来自 IB 的实际 NIB 信息的情况下分配了控制 Class。
代替
GuitarBrandsViewController *screen = [[GuitarBrandsViewController alloc] initWithNibName:nil bundle:nil];
利用
GuitarBrandsViewController *screen = [[GuitarBrandsViewController alloc] initWithNibName:@"GuitarBrandsViewController.xib" bundle:nil];
将笔尖名称调整为您使用的实际笔尖的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.