2012-01-04 189 views
0

當按鈕被點擊時,我得到了一個IBACtion按鈕,它打開了一個新的視圖。當點擊按鈕時,我得到了EXC_BAD_ACCESS.i啓用了NSZOMBIE,它顯示了最後一行函數 - (無效)的主頁可以幫助你我..下面是代碼。EXC_BAD_ACESS當IBAction按鈕被點擊時

splashscreen.h

@interface SplashScreen : UIViewController { 
HomePage *newEnterNameController; 
} 

@property(nonatomic,retain)HomePage *newEnterNameController; 
@end 

splashscreen.m

@implementation SplashScreen 
    @synthesize newEnterNameController; 


     -(void)homepage 
     { 
    self.newEnterNameController = [[HomePage new] initWithNibName:@"HomePage"bundle: 
     [NSBundle mainBundle]]; 
     [newEnterNameController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:self.newEnterNameController animated:YES]; 
    } 

    - (void)dealloc { 
    [self.newEnterNameController release]; 
     [super dealloc]; 

     } 


@end 
+1

在'homepage'方法的第一個語句中,您希望'alloc'而不是'new',並且您需要添加'autorelease'消息以避免泄漏,導致:'self.newEnterNameController = [[[HomePage alloc ] initWithNibName:@「HomePage」包: [NSBundle mainBundle]] autorelease];' – albertamg 2012-01-04 12:11:10

+0

cud u給我一個小例子來說明如何做到這一點。 – kingston 2012-01-04 12:14:19

+0

'[self presentModalViewController:self.snewEnterNameController animated:YES];'你能否修復這個錯字('self。* s * new ...') – 2012-01-04 12:32:36

回答

0
self.newEnterNameController = [[HomePage new] initWithNibName:@"HomePage"bundle: [NSBundle mainBundle]]; 

[Class new]等於[[Class alloc] init],所以你正在初始化對象兩次。此行或許應該是這樣的:

self.newEnterNameController = [[HomePage alloc] initWithNibName:@"HomePage"bundle: [NSBundle mainBundle]]; 
+0

仍然獲得EXC_BAD_ACESS – kingston 2012-01-04 12:27:12

+0

我想到了它的主頁視圖在模態視圖 – kingston 2012-01-04 14:07:46

0

取代 - (無效)網頁上的 - (IBAction爲)主頁:(ID)發送方,並且從界面生成器重新鏈接按鈕,或編程取決於你的UIButton創建代碼

+0

仍然變糟的獲取 – kingston 2012-01-04 12:28:52

0

,而不是這樣的:

-(void)homepage 
    { 
self.newEnterNameController = [[HomePage new] initWithNibName:@"HomePage"bundle: 
    [NSBundle mainBundle]]; 
    [newEnterNameController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
[self presentModalViewController:self.snewEnterNameController animated:YES]; 
} 

嘗試爲:

-(IBAction)homepage 
    { 
self.newEnterNameController = [[[HomePage alloc] initWithNibName:@"HomePage"bundle: 
    [NSBundle mainBundle]]autorelease]; 
    [newEnterNameController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
[self presentModalViewController:self.snewEnterNameController animated:YES]; 
} 

這個接口builder.Now看到的結果是連接到您的按鈕。

+0

中打開的問題你是對的,他必須使用alloc。 .. – 2012-02-13 07:59:52