单击IBAction按钮时的EXC_BAD_ACCESS

时间:2012-01-04 12:00:01

标签: objective-c xcode

单击按钮时,我有一个IBACtion按钮。打开一个新视图。点击按钮后,我获得了EXC_BAD_ACCESS.i启用了NSZOMBIE,它显示了函数中的最后一行 - (void)主页你们可以帮帮我......下面是代码。

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

3 个答案:

答案 0 :(得分:0)

用 - (IBAction)主页替换 - (void)主页:( id)sender,并从界面构建器重新链接按钮,或者以编程方式重新链接,具体取决于您的UIButton创建代码

答案 1 :(得分:0)

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

[Class new]等于[[Class alloc] init],因此您要初始化对象两次。这一行应该如下所示:

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

答案 2 :(得分: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];
 }

并将其连接到界面构建器中的按钮。现在看到结果。