2011-06-14 108 views
1

我的應用程序是一個標籤欄的應用程序。有在底部的兩個標籤和一個按鈕,導致一個新的窗口,第一個選項卡上的電源插座。當我在xcode中構建代碼時,它會成功。當我在模擬器中啓動應用程序並單擊指向新窗口的按鈕時,它會使應用程序崩潰。這是我對 「FirstViewController」 和 「GuitarBrandsViewController」 代碼應用在iPhone模擬器崩潰。 Xcode中3.2.5

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]; 
} 

GuitarBrandsView或者Controller.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

這就是爲什麼我不使用Interface Builder一個很好的例子。這是一個痛苦的尋求幫助......有沒有辦法讓我們判斷你的控件已正確連接到您的選擇... – 2011-06-14 23:32:40

+0

並通過Xcode中顯示哪些錯誤? – 2011-06-14 23:33:58

回答

1

我假設你正在使用界面生成器作爲類本身的代碼不會在它自己的工作,創造了GuitarBrandsViewController。

然而,當你初始化GuitarBrandsViewController,你不要這樣,你沒有從IB實際NIB信息分配控制類通過NIB。

而不是

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

使用

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

調整筆尖名字你實際使用的筆尖的名稱。