我试图通过代码隐藏tableview加载时的detailTextLabel.cell,
cell.textLabel.text=[array objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row];
cell.detailTextLabel.hidden = YES;
在选择该行时,尝试在didSelectRowAtIndexPath中显示detailarray,正如预期的那样,在按该行的同时显示detailarray,一旦我停止按下它,detailarray文本就会消失,为什么会这样,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"indexpath is %d", indexPath.row);
selectedIndex = indexPath.row;
isSearching = YES;
[self.tableview beginUpdates];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[dealarray objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row];
cell.detailTextLabel.hidden = NO;
[self.tableview endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearching && indexPath.row == selectedIndex)
{
return 77;
}
return 44;
}
编辑:
在.h文件中分配了变量“ a”,并按如下所示使用了代码,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text=[dealarray objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row];
NSLog(@"dealarray %@\n %@",dealarray,detailarray);
if (a==-1) {
cell.detailTextLabel.hidden = YES;
}
else if(a==indexPath.row)
{
cell.detailTextLabel.hidden = NO;
}
else cell.detailTextLabel.hidden = YES;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"indexpath is %d", indexPath.row);
selectedIndex = indexPath.row;
isSearching = YES;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[dealarray objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row];
a=indexPath.row;
[tableview reloadData];
}
最佳答案
为此,您可以使用两种类型的单元格。
对于正常数据,请使用基本单元格。选择后,重新加载表或单元格,并使用另一个detailLabel单元格仅用于选定的行。
它将解决您的问题。
谢谢
关于ios - 在uitableview中隐藏/显示detailTextLabel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18613902/