我正在做一个需要扩展单元格 onclick 以显示更多详细信息的应用程序。我使用了一个自定义单元并将它们添加到 UItableview 中。当我单击单元格时,它的动画效果很好并下降,当我再次单击时它上升,这是通过更改单元格的高度来完成的。实际的自定义单元格大小比我通常显示的单元格大。当我单击单元格时,会显示整个单元格。我遇到的唯一问题是数据溢出。未选择单元格时应隐藏这些数据。只有当它被选中时,才应该显示这些数据。
我参考了不同的文章,尝试更改颜色设置绑定对我不起作用。我在这个问题iphone uitablecellview overflow中遇到了同样的问题,尝试了答案,但没有奏效。
我所需要的只是如何在自定义单元格未扩展时隐藏它的底部,并在扩展时显示它......!
这些是我的屏幕截图
加载
时单击单元格
时]单击第二个单元格
时单击已展开的单元格时这些是我使用过的代码片段...。
// Declaring the SearchResultTable.
CGRect filterFrame = CGRectMake(0,31, 320, 400);
self.searchResultTable = [[UITableView alloc] initWithFrame:filterFrame];
self.searchResultTable.dataSource = self;
self.searchResultTable.delegate = self;
self.searchResultTable.backgroundColor = [UIColor whiteColor];
self.searchResultTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.searchResultTable.separatorColor = [UIColor lightGrayColor];
[self.view addSubview:self.searchResultTable];
//Adding cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ExpandedSearchResultTableCell";
ExpandedSearchResultTableCell *cell = (ExpandedSearchResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell.contentView.clipsToBounds = YES;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExpandedSearchResultTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.productNameLable.text = @"Only this should be shown";
cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded";
cell.productApplicationLable.text=@"This Should be hidden.. Only shown when expanded";
cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded";
cell.productQuantityLable.text=@"This Should be hidden.. Only shown when expanded";
cell.productReactivityLable.text=@"This Should be hidden.. Only shown when expanded";;
return cell;
}
//on click event
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Deselect cell
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
// Toggle 'selected' state
BOOL isSelected = ![self cellIsSelected:indexPath];
// Store cell 'selected' state keyed on indexPath
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath];
// This is where magic happens...
[searchResultTable beginUpdates];
[searchResultTable endUpdates];
}
//Getting the height depending on expanded or not
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// If our cell is selected, return double height
if([self cellIsSelected:indexPath]) {
return kCellHeight * 3.0;
}
// Cell isn't selected so return single height
return kCellHeight;
}