У меня есть UITextView в UITableViewCell в раскадровке. Затем я добавил ограничение на все 4 стороны UITextView.Авто размер ячейки на основе UITextView
В приведенном ниже коде я попытался сделать textView динамически меняющимся, когда пользователь вводит текст. Я уверен, что сработал успешно. Но проблема в том, что клетка - нет. Bellow - это код, который я пробовал, но безуспешно.
-(void)viewDidLoad
{
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = 44;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (textView == myTextView)
{
[self textViewFitToContent:myTextView];
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
return YES;
}
- (void)textViewFitToContent:(UITextView *)textView
{
CGFloat fixedWidth = textView.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
textView.frame = newFrame;
textView.scrollEnabled = NO;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return myTextView.frame.size.height + 40;
}
Я новичок, поэтому, пожалуйста, не слишком грубый на меня.
Благодаря
Все ячейки меняют высоту, когда предполагается только один. –