gpt4 book ai didi

iphone - Tableview 中的 UITextView 文本得到覆盖?

转载 作者:行者123 更新时间:2023-11-28 18:39:41 25 4
gpt4 key购买 nike

在我的应用程序中,我使用四个 UITextView 自定义了 UITableView Cell。每当我将数据添加到 TableView 并重新加载它时。 UITableViewCell 中的文本被之前的文本覆盖。

我尝试了不同的方法,但无法弄清楚问题出在哪里。

我在 View Controller 中使用 TableView。

这是我在表格 View 单元格中使用的代码?

if ( [tableView isEqual:self.tableActions])
{
//Setting the text empty

static NSString *CellIdentifier = @"ActionsIdentifier";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
NSLog(@"Index Path %i",[indexPath row]);
ActionDetails *actiondetails = [actionArray objectAtIndex:[indexPath row]];

NSLog(@"Action Text %@",actiondetails.actions);

//Actions
actionText=[[UITextView alloc] initWithFrame:CGRectMake(10, 5, 230,30)];
actionText.font = [UIFont systemFontOfSize:17.0];
actionText.editable = NO;
actionText.textColor=[UIColor blackColor];
actionText.text = actiondetails.actions ;
actionText.userInteractionEnabled = NO;
actionText.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:actionText];


//Owner
ownerBy=[[UITextView alloc] initWithFrame:CGRectMake(230, 5, 230,30)];
ownerBy.font = [UIFont systemFontOfSize:17.0];
ownerBy.textColor=[UIColor blackColor];
ownerBy.textAlignment = UITextAlignmentCenter;
ownerBy.text = actiondetails.owner;
ownerBy.editable = NO;
ownerBy.userInteractionEnabled = NO;
ownerBy.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:ownerBy];

}

截图 enter image description here

感谢您的帮助。

非常感谢。

最佳答案

这件事前几天发生在我身上,我想出的解决方案是在 if 语句中创建单元格后从单元格中删除所有 subview 。

if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}

关于iphone - Tableview 中的 UITextView 文本得到覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12745091/

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