Iphone UITextView表格视图中的文本是否获得覆盖?
在我的应用程序中,我为UITableView单元格定制了四个UITextView。每当我将数据添加到tableview并重新加载它时。UITableViewCell中的文本将被以前的文本覆盖 我尝试了不同的方法,但不知道问题出在哪里 我正在视图控制器中使用TableView 这是我在表格视图单元格中使用的代码Iphone UITextView表格视图中的文本是否获得覆盖?,iphone,ios,uitableview,Iphone,Ios,Uitableview,在我的应用程序中,我为UITableView单元格定制了四个UITextView。每当我将数据添加到tableview并重新加载它时。UITableViewCell中的文本将被以前的文本覆盖 我尝试了不同的方法,但不知道问题出在哪里 我正在视图控制器中使用TableView 这是我在表格视图单元格中使用的代码 if ( [tableView isEqual:self.tableActions]) { //Setting the text empty static NSStrin
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];
}
截图
谢谢你们的帮助
非常感谢。删除Tableview的单元格标识符,否则将使用Customcell作为Tableview。删除Tableview的单元格标识符,否则将使用Customcell作为Tableview。简单尝试以下方法:
{
//Setting the text empty
static NSString *CellIdentifier = @"ActionsIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
**// if(cell == nil) // comment this line in your code ,its work
// {**
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];
}
只需简单地尝试以下方法:
{
//Setting the text empty
static NSString *CellIdentifier = @"ActionsIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
**// if(cell == nil) // comment this line in your code ,its work
// {**
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];
}
您正在重复使用该单元。重用的单元格已经添加了UITextview。因此您正在覆盖它。 必须将创建和添加UITextView的所有代码移到 如果(单元格==nil) { }
之后,您只需将文本设置为UITextview。您正在重用单元格。重用的单元格已经添加了UITextview。因此您正在覆盖它。 必须将创建和添加UITextView的所有代码移到 如果(单元格==nil) { }
之后,只需将文本设置为UITextview。当视图出现时,写入并重新加载表视图
-(void)viewDidAppear:(BOOL)animated {
[tableView reloadData];
}
当视图出现时,请写入并重新加载表视图
-(void)viewDidAppear:(BOOL)animated {
[tableView reloadData];
}
前几天我遇到了这种情况,我提出的解决方案是在if语句中创建单元格后,从单元格中删除所有子视图
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];
}
}
前几天我遇到了这种情况,我提出的解决方案是在if语句中创建单元格后,从单元格中删除所有子视图
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];
}
}
更改
cellforrowatinexpath
方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// your code
}
// your code
return cell;
}
更改
cellforrowatinexpath
方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// your code
}
// your code
return cell;
}
谢谢你的回复。对不起,什么是删除单元格标识符或为TableView获取customcell在代码中您已获取cellidentifier删除此项并将单元格标识符设置为nil<代码>单元格=[tableView dequeueReusableCellWithIdentifier:nil]代码>和在
单元格中=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:nil]代码>你们在重复使用电池,这就是问题发生的原因。另一种方法是andypaul的答案。。请参见下文当我在单元格标识中使用nil时,单击事件在tableview中不起作用感谢您的回复。对不起,什么是删除单元格标识符或为TableView获取customcell在代码中您已获取cellidentifier删除此项并将单元格标识符设置为nil<代码>单元格=[tableView dequeueReusableCellWithIdentifier:nil]代码>和在单元格中=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:nil]代码>你们在重复使用电池,这就是问题发生的原因。另一种方法是andypaul的答案。。请参见下文。当我在单元格标识中使用nil时,单击事件在tableview中不起作用感谢您的答案伙计们+1表示您的所有支持。您得到解决方案了吗。我也有同样的问题谢谢你的回答伙计们+1谢谢你的支持..你有解决这个问题的方法吗。我也有同样的问题