简体   繁体   English

Thread1 exc_bad_access(代码= 2)…帮助我

[英]Thread1 exc_bad_access (code =2)… help me

i've been fixing this problem for a few days. 我已经解决了几天这个问题。 but can't seem to get it.. help me out .. 但似乎无法得到..帮助我..

let me explain my situation. 让我解释一下我的情况。 Basically, i have navigation controller that contains table view controller and view controller. 基本上,我有包含表视图控制器和视图控制器的导航控制器。 and i'm making simple phone book app. 而且我正在制作简单的电话簿应用程序。

And, i have a directory entry declared in extension class 而且,我在扩展类中声明了一个目录条目

@interface DetailViewController ()

@property DirectoryEntry *dirEntry;

@end

And, in table view, when you click the button it will transfer some data through segue 并且,在表格视图中,当您单击按钮时,它将通过segue传输一些数据

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    DetailViewController *detailCV = [segue destinationViewController];

    if ([segue.identifier isEqualToString:@"cellToDetail"]) {

        [detailCV setDirEntry: [self.pbArray objectAtIndex:[self.tableView     indexPathForSelectedRow].row]];

    } else {

        detailCV.dirEntry = nil;

    }

    //designate delegate !!!
    detailCV.delegate = self;

}

My Problem occurs when it execute detailCV.dirEntry = nil; 我的问题在执行detailCV.dirEntry = nil时发生 it will call my setter in viewController. 它将在viewController中调用我的setter。 it says EXC_BAD_ACCESS 说EXC_BAD_ACCESS

 -(void) setDirEntry:(DirectoryEntry *) dirEntry {
    self.dirEntry  = dirEntry;
}

Thank you in advance.. 先感谢您..

It's not an EXC_BAD_ACCESS so much as the OS killing your app for smashing the stack. 它不是EXC_BAD_ACCESS,而是OS杀死您的应用以破坏堆栈而已。 This method is recursing infinitely: 此方法无限递归:

-(void) setDirEntry:(DirectoryEntry *) dirEntry {
    self.dirEntry  = dirEntry;
}

Your use of dot notation expands to a setter which should make this more clear. 您对点表示法的使用将扩展为设置器,这应该使它更加清楚。

-(void) setDirEntry:(DirectoryEntry *) dirEntry {
    [self setDirEntry:dirEntry];
}

Set the instance variable directly, or let the compiler handle it. 直接设置实例变量,或让编译器处理它。 Properties in class extensions are automatically synthesized. 类扩展中的属性是自动合成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM