2017-09-27 164 views
1

我使用MRC(不使用ARC)我想這個代碼,但得到錯誤 「EXC_BAD_ACCESS」 在titleForHeaderInSection

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

b滾動比錯誤不良訪問。 Helpme

回答

1

你headerTitle是assign是一樣,你必須保持它保留

替換代碼

@property (nonatomic, assign) NSString* headerTitle; 

@property (nonatomic, retain) NSString* headerTitle; 

編輯


非ARC需要使用。 release

+0

謝謝你的回答,但我使用的是MRC版本。替換爲「保留」?當調用釋放? –

+0

我只有ARC的想法,按照我'retain'是一個很好用,如果你不使用ARC,那麼你需要手動'釋放'對象'nil'在這裏不會工作:) –

+0

感謝您的幫助。 :) –

相關問題