我创建了一个UITableViewCell,里面有一个UITextView。 我正在使用Json为Textview获取我的Html内容。我也使用DTCoreText。在这里我cellForRowAtIndexPath:
单元格内容(Textview)只触摸单元格后更新
static NSString *CellIdentifier1 = @"NewsCell";
GTNewsCustomCell *newsCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if(newsCell == nil){
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"GTNewsCustomCell"
owner:self//transfer ownership to self
options:nil];
newsCell = [nibViews objectAtIndex:0];
}
newsCell.cellFrame = CGRectMake(10, 0, 300,40);
newsCell.titleLabel.text = [[self.newsList objectAtIndex:indexPath.section]objectForKey:@"title"];
newsCell.messageTextView.textColor = [UIColor blackColor];
newsCell.messageTextView.backgroundColor = GTDefaultTextBackgroundColor;
newsCell.messageTextView.editable = NO;
newsCell.messageTextView.userInteractionEnabled = NO;
newsCell.messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
NSString *htmlTag = @"<b></b>";
NSString *html = [NSString stringWithFormat:@"%@%@",htmlTag,[[self.newsList objectAtIndex:indexPath.section]objectForKey:@"previewMessage"]];
.
.
.
return newsCell;
问题的一部分原因是我的TextView的内容有时比TextView的尺寸更大。奇怪的是,当我触摸textview,它更新自己,每个人都显示正确....什么可能是错的?
这里有一些截图:
破碎的TextView:
当我接触到的细胞,文本的格式:
编辑: 否我已经找到我的问题,但我不知道如何解决它。在我的自定义单元格.m文件我有变革的方法进行的单元尺寸宽度:
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect cellRect = self.bounds;
cellRect.size.width = self.cellFrame.size.width;
self.bounds = cellRect;
}
如果我删除一切工作正常,但当然我的手机没有正确的大小了......但我需要TableView和Cell之间从左到右的一些空间!
你可以减少一些问题,如在找到最小数量的代码重现问题? –
我希望它更好地知道:) – Davis