Search code examples
iosobjective-cexc-bad-access

I tried this code but get error "EXC_BAD_ACCESS" In titleForHeaderInSection


i'm Using MRC(do not use ARC)

section.h

@property (nonatomic, assign) NSString* headerTitle;

section.m

- (instancetype)initwhithHeaderTitle:(NSString *)headerTitle {
    self.headerTitle = headerTitle;
}
- (void)dealloc {
    self.headerTitle = nil;
}

tableview.m

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return self.sections[section].headerTitle;
}

but scroll than error BAD ACCESS. Helpme


Solution

  • Your headerTitle is assign it is same as weak , You must keep it retain

    Replace your code

    @property (nonatomic, assign) NSString* headerTitle;
    

    with

    @property (nonatomic, retain) NSString* headerTitle;
    

    EDIT


    non ARC you need to use . release