我正在做一个需要扩展单元格 onclick 以显示更多详细信息的应用程序。我使用了自定义单元格并将它们添加到 UItableview。当我单击单元格时,它会很好地设置动画并向下移动,当我再次单击时,它会上升,这是通过更改单元格的高度来完成的。实际自定义单元格大小比我通常显示的单元格大。当我单击单元格时,会显示整个单元格。我遇到的唯一问题是数据溢出。未选择单元格时应隐藏这些数据。只有当它被选中时,才应该显示这些数据。
我引用了不同的文章,尝试更改颜色设置绑定(bind)对我不起作用。 我在这个问题中有同样的问题 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;
}
最佳答案
如果您正在寻找具有普通 tableview 类型的单元格扩展,
iPhone UITableView with animated expanding cells
如果您正在使用分组 TableView 并希望扩展节标题的选择,
关于objective-c - UItable 单元格溢出 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12176193/