[英]UITableViewCell which shows subview on touch and hides it on second touch
我需要创建特定的tableViewCell ,它在第一次触摸时显示一个特殊的子视图,并在第二次触摸时隐藏它。该子视图包含一些标签或按钮。
在cellForRowAtIndexPath
,将tag
属性添加到相关单元格的子视图中。 同时将子视图的hidden
属性设置为YES
。 最后,将单元格的selectionStyle
设置为UITableViewCellSelectionStyleNone
。
if (thisIsTheIndexPathInQuestion) {
CGRect theFrame = CGRectMake(...); // figure out the geometry first
UIView *subview = [[UIView alloc] initWithFrame:theFrame];
// further customize your subview
subview.tag = kSubViewTag; // define this elsewhere, any random integer will do
subview.hidden = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView addSubView:subview];
[subview release];
}
然后只对您在相应的UITableView委托方法中描述的内容作出反应:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (thisIsTheIndexPathInQuestion) { // you know how to check this
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UIView *subview = [cell viewWithTag:kSubViewTag];
subview.hidden = !subview.hidden; // toggle if visible
}
}
确保您的“特殊”单元格具有不同的CellIdentifier
,这将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.