【发布时间】:2015-07-21 12:05:04
【问题描述】:
嗨,我是 Ios 的初学者,在我的项目中,我在 UItableview 单元格上添加了 UItextView,并根据 textlength 自动增加 UItextview 和 UItableview 单元格的高度,但根据我的代码,所有 textdata 都没有显示在 textview 上,有些数据丢失了请帮助我某一个
这是我的代码:
formulaArray = [NSArray arrayWithObjects:@"Implement exponential back-off in your retry mechanism. (e.g. if you waited one second before the first retry,Implement exponential back-off in your retry mechanism. (e.g. if you waited one second before the first retry,Implement exponential back-off in your retry mechanism. (e.g. if you waited one second before the first retry,Implement exponential back-off in your retry mechanism. (e.g. if you waited one second before the first retry,finally",nil];
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cellIdentifier";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
if(indexPath.section == 1)
{
formulaText = [[UITextView alloc]init];
formulaText.font = [UIFont fontWithName:@"Bitter-Regular" size:15.0f];
formulaText.translatesAutoresizingMaskIntoConstraints = NO;
formulaText.backgroundColor = [UIColor lightGrayColor];
formulaText.scrollEnabled = NO;
[cell.contentView addSubview:formulaText];
NSDictionary * views = NSDictionaryOfVariableBindings(formulaText);
NSArray * formulaH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[formulaText]-10-|"
options:0
metrics:nil
views:views];
NSArray * formulaV = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[formulaText]-5-|"
options:0
metrics:nil
views:views];
[cell.contentView addConstraints:formulaH];
[cell.contentView addConstraints:formulaV];
formulaText.text = [formulaArray objectAtIndex:0];
#define kMaxHeight 100.f
formulaText.contentSize = [formulaText.text sizeWithFont:[UIFont fontWithName:@"Bitter-Regular" size:15.0]
constrainedToSize:CGSizeMake(100, kMaxHeight)
lineBreakMode:NSLineBreakByWordWrapping];
}
if (indexPath.section == 2)
{
aboutText = [[UITextView alloc]init];
aboutText.font = [UIFont fontWithName:@"Bitter-Regular" size:15.0f];
aboutText.translatesAutoresizingMaskIntoConstraints = NO;
aboutText.backgroundColor = [UIColor darkGrayColor];
aboutText.scrollEnabled = NO;
[cell.contentView addSubview:aboutText];
NSDictionary * views = NSDictionaryOfVariableBindings(aboutText);
NSArray * formulaH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[aboutText]-10-|"
options:0
metrics:nil
views:views];
NSArray * formulaV = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[aboutText]-5-|"
options:0
metrics:nil
views:views];
[cell.contentView addConstraints:formulaH];
[cell.contentView addConstraints:formulaV];
aboutText.text = [aboutArray objectAtIndex:0];
#define kMaxHeight 100.f
aboutText.contentSize = [aboutText.text sizeWithFont:[UIFont fontWithName:@"Bitter-Regular" size:15.0]
constrainedToSize:CGSizeMake(100, kMaxHeight)
lineBreakMode:NSLineBreakByWordWrapping];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//return 200;
if([indexPath section] == 0)
{
return 200;
}
else if([indexPath section] == 1)
{
NSString *cellText = [formulaArray objectAtIndex:0];
UIFont *cellFont = [self fontForCell];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
return labelSize.height + 20;
}
else
{
NSString *cellText = [aboutArray objectAtIndex:0];
UIFont *cellFont = [self fontForCell];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
return labelSize.height + 20;
}
}
但是这里的公式数组所有 text 数据没有显示请帮帮我
【问题讨论】:
标签: ios objective-c