我试过这段代码,但在 titleForHeaderInSection 中出现错误 "EXC_BAD_ACCESS"

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

我正在使用 MRC(不使用 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;
}

但滚动时出现错误 BAD ACCESS。帮帮我

你的 headerTitle 是 assignweak 一样,你必须保留它 retain

替换您的代码

@property (nonatomic, assign) NSString* headerTitle;

@property (nonatomic, retain) NSString* headerTitle;

编辑


您需要使用非 ARC。 release