Objective c 单击iAction按钮时执行错误访问
单击按钮时,我得到了一个iAction按钮。它打开了一个新视图。单击按钮时,我获得了EXC\u BAD\u访问权限。我启用了NSZOMBIE,它显示了函数-(void)主页中的最后一行,请大家帮我解决。下面是代码 飞溅屏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
@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响应我想问题出在模式视图中打开的主页视图中