Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 单击iAction按钮时执行错误访问_Objective C_Xcode - Fatal编程技术网

Objective c 单击iAction按钮时执行错误访问

Objective c 单击iAction按钮时执行错误访问,objective-c,xcode,Objective C,Xcode,单击按钮时,我得到了一个iAction按钮。它打开了一个新视图。单击按钮时,我获得了EXC\u BAD\u访问权限。我启用了NSZOMBIE,它显示了函数-(void)主页中的最后一行,请大家帮我解决。下面是代码 飞溅屏 @interface SplashScreen : UIViewController { HomePage *newEnterNameController; } @property(nonatomic,retain)HomePage *newEnterNameControl

单击按钮时,我得到了一个iAction按钮。它打开了一个新视图。单击按钮时,我获得了EXC\u BAD\u访问权限。我启用了NSZOMBIE,它显示了函数-(void)主页中的最后一行,请大家帮我解决。下面是代码

飞溅屏

@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
将-(void)homepage替换为-(iAction)homepage:(id)sender,然后从interface builder重新链接按钮,或者根据UIButton创建代码以编程方式重新链接按钮

self.newEnterNameController = [[HomePage new] initWithNibName:@"HomePage"bundle:    [NSBundle mainBundle]];
[Class new]
等于
[[Class alloc]init]
,所以要初始化对象两次。这一行可能如下所示:

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

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

然后将其连接到interface builder中的按钮。现在查看结果。

主页
方法的第一条语句中,您需要
alloc
而不是
new
,并且需要添加一条
自动删除
消息,以避免泄漏导致:
self.newEnterNameController=[[[homepage alloc]initWithNibName:@“主页”包:[NSBundle mainBundle]]自动释放]
cud你给我一个小例子来说明如何做到这一点。
[self-presentModalViewController:self.snewineternamecontroller:YES]
你能修复这个输入错误吗(
self.*s*new…
)试着在控制台中写“backtrace”,看看到底是什么代码导致应用程序崩溃,如果可能的话,在这里发布backtrace响应我想问题出在模式视图中打开的主页视图中