-1
当您选择一个tableviewcell时,它将从44像素扩展到100像素,而当您取消选择时它将再次收缩到44像素。在底部展开Tableviewcell揭示标签
在故事板中,我已将自己的单元格定制为100像素,并添加了3个标签。一个在顶部,两个在底部(底部的2个标签不应该可见并隐藏在底部)。
当我运行我的应用程序时,每个单元格将获得44像素的高度。底部的两个标签在正确的x坐标处可见,但在每个其他单元格上方都可见。 这样的:
在viewDidLoad中:
self.expandedIndexPath = [NSIndexPath indexPathForRow:7 inSection:1];
而且方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Compares the index path for the current cell to the index path stored in the expanded
// index path variable. If the two match, return a height of 100 points, otherwise return
// a height of 44 points.
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
return 100.0; // Expanded height
}
return 44.0; // Normal height
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *DateName = (UILabel *)[cell viewWithTag:100100];
DateName.text = _objects[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates];
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
self.expandedIndexPath = nil;
} else {
self.expandedIndexPath = indexPath;
}
[tableView endUpdates];
}
如何隐藏标签,直至细胞扩增到100个像素?
您是否有任何问题? – 2014-09-29 17:19:01
我编辑了我的问题。 – Dridia 2014-09-29 17:25:50
问题是以'?'结尾的句子。 – 2014-09-29 17:27:02