EXC_BAD_ACCESS in heightForRowAtIndexPath iOS
Я работаю над приложением, в котором у меня есть собственный подкласс UITableViewCell. Я хочу, чтобы высота ячейки была динамичной на основе текста внутри нее. Я пытаюсь сделать это в моем методе heightForRowAtIndexPath. Но у меня есть некоторые проблемы, следующий код вызывает ошибку EXC_BAD_ACCESS (code = 2 address = 0xb7ffffcc).
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
PostCell *cell = (PostCell *)[tableView cellForRowAtIndexPath:indexPath];
CGSize postTextSize;
if (![cell.postText.text isEqualToString:@""]) {
postTextSize = [cell.postText.text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(cell.postText.frame.size.width, 200)];
} else {
postTextSize = CGSizeMake(cell.postText.frame.size.width, 40);
}
return postTextSize.height + cell.userName.frame.size.height + 10;
}
Если у меня вместо этого есть:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
Оно работает.
Кажется, сбой в этой строке:PostCell *cell = (PostCell *)[tableView cellForRowAtIndexPath:indexPath];
и я не знаю почему. Я пытался собрать чистый и сбросить симулятор, но ни один не работал. Есть идеи, почему это происходит?