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

标签 iphone ios uitableview

在我的应用程序中,我使用四个 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/

相关文章:

iphone - 什么最能解释 [myVar dealloc] 和 [myVar release] 之​​间的区别?

iphone - 如何在 UITableView 中显示 NSMutableDictionary 数据数组?

iphone - 如何将 UIGestureRecognizer 添加到 UITableViewCell subview ?

ios - 共享自定义框架而不共享代码

ios - 查看将消失 : Determine whether view controller is being popped or is showing a sub-view controller

ios - UITableViewCell 中的 UserDefaults 不保存 (swift3)

ios - 给定 UITableViewCell 的 indexPath,加载该特定单元格

iphone - Objective-C/iPhone IRC 库

ios - JSQMessagesViewController 显示用户名

iphone - UITableView 分隔符问题