Reputation: 21726
I need to create specific tableViewCell ,which shows a special subview on first touch and hides it on second touch That subview contains some labels or buttons.
Upvotes: 4
Views: 1236
Reputation: 80265
In cellForRowAtIndexPath
, add a tag
property to the subview of the cell in question. Also set the subview's hidden
property to YES
. Finally, set the cell's selectionStyle
to 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];
}
Then just react to what you describe in the appropriate UITableView delegate method:
- (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
}
}
Make sure your "special" cell has a different CellIdentifier
and this will work.
Upvotes: 5