gpt4 book ai didi

ios - 如何根据其在textview中的内容更改自定义tableview单元格高度和textview高度

转载 作者:行者123 更新时间:2023-12-01 16:26:04 25 4
gpt4 key购买 nike

我已经创建了一个自定义单元格与textview。我需要在不使用自动布局的情况下根据textview中的内容来扩展textview的高度和自定义单元格的高度。谁能帮我

Cell design
这是代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return sendername.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier1 = @"MenuCtrl";

tsecureMsgConCell *cell = [tabVieConv dequeueReusableCellWithIdentifier:CellIdentifier1];

if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MsgConCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}

cell.userName.text = [sendername objectAtIndex:indexPath.row];
cell.msgContentTxView.text = [msgContents objectAtIndex:indexPath.row];


NSString * sentDateCell = [msgSenddate objectAtIndex:indexPath.row];
NSString * replyDateCell = [msgRevidate objectAtIndex:indexPath.row];
thredIdCell = [TSecureMsgId objectAtIndex:indexPath.row];

if ([sentDateCell isEqualToString:@"NULL"])
{
cell.dateLbl.text = [msgRevidate objectAtIndex:indexPath.row];
cell.timeLbl.text = [msgRecTime objectAtIndex:indexPath.row];
cell.imgVew.image = [UIImage imageNamed:@"recive.png"];
}

else if ([replyDateCell isEqualToString:@"NULL"])
{
cell.dateLbl.text = [msgSenddate objectAtIndex:indexPath.row];
cell.timeLbl.text = [msgSendTime objectAtIndex:indexPath.row];
cell.imgVew.image = [UIImage imageNamed:@"sent.png"];
}

return cell;

}

msgContentTxView-是我的textview

最佳答案

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = indexPath.row;
if (row != NSNotFound)
{


if ([exapmlestring length] > 0)
{
CGFloat padding = 17.0f;

CGFloat labelWidth = self.tableview.bounds.size.width - padding*2;
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"HelveticaNeue" size:17.0], NSFontAttributeName,
nil];

NSAttributedString *text = [[NSAttributedString alloc] initWithString:exapmlestring attributes:attributesDictionary];
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin;

///size
CGRect boundingRect = [text boundingRectWithSize:CGSizeMake(labelWidth, CGFLOAT_MAX)
options:options
context:nil];


boundingRect.size.height = boundingRect.size.height + 100;

return (CGFloat) (ceil(boundingRect.size.height) + padding*2);
}
}

return 0;
}

关于ios - 如何根据其在textview中的内容更改自定义tableview单元格高度和textview高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35307196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com