2012-01-04 144 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