我的应用是标签栏应用。底部有两个标签,第一个标签上有一个插座,带有一个通向新窗口的按钮。当我在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];
}
答案 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];
将笔尖名称调整为您使用的实际笔尖的名称。