我创建了一个表格视图,并在 uitableviewcell 中添加了两个 uitextview,它运行良好,但是当我加载时数据不显示完整数据,当我滚动表格视图时它加载,数据将显示在单元格中。所以任何人都可以告诉我。有什么问题,并告诉我如何为 textview 制作灵活的单元格长度
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier ];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
txtView1 = [[UITextView alloc]initWithFrame:CGRectMake(0, 10, 320,100)];
txtView1.text =entry.articleTitle;
txtView1.editable = NO;
txtView1.font = [UIFont systemFontOfSize:20];
txtView1.textColor = [UIColor blackColor];
txtView1.delegate = self;
txtView1.textAlignment = UITextAlignmentLeft;
txtView1.scrollEnabled = NO;
int a= entry.articleSummary.length;
if(a < 100)
{
txtView2 = [[UITextView alloc]initWithFrame:CGRectMake(0, 70, 320, 100)];
}
else if(a <200)
{
txtView2 = [[UITextView alloc]initWithFrame:CGRectMake(0, 70, 320, 300)];
}
else
{
txtView2 = [[UITextView alloc]initWithFrame:CGRectMake(0, 70, 320, 400)];
}
txtView2.text = entry.articleSummary;
txtView2.editable = NO;
txtView2.font = [UIFont systemFontOfSize:16];
txtView2.textColor = [UIColor blackColor];
txtView2.delegate = self;
txtView2.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:txtView1];
[cell.contentView addSubview:txtView2];
return cell;
}