hklel
hklel

Reputation: 1634

Hide a custom UITableViewCell from another UITableViewCell class

I have two cells, let's say cell A and cell B in my app. Both of them have their own class, class CellA : UITableViewCell and class CellB : UITableViewCell.

I wish to hide cell B when user tap on a button in cell A.

How can I achieve this? Thanks.

Upvotes: 0

Views: 55

Answers (2)

Saheb Roy
Saheb Roy

Reputation: 5967

If you are using Static tableview content, just create two outlet of cell, lets say Cell1 and Cell2 with respective class of A and B with action methods actn_methodCell1 and actn_methodCell2

-(void)actn_methodCell1{ //action method for button in cell1
Cell2.hidden = YES;
[self.tableview reloadData];
}
 -(void)actn_methodCell2{ //action method for button in cell2
Cell1.hidden = YES;
[self.tableview reloadData];
}

OR If you are using prototype tableview then, code this in didSelectCell

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:    (NSIndexPath *)indexPath{
       UITableViewCell *cell = [self.tableview cellForRowAtIndexPath:indexPath.row];
if([cell isKindOfClass:[A class]]){
        for (UITableViewCell *cell in self.tableview) {
    if([cell isKindOfClass:[B class]]){
        cell.hidden = YES;
    }
}
}
else if ([cell isKindOfClass:[B class]]){  
for (UITableViewCell *cell in self.tableview) {
    if([cell isKindOfClass:[A class]]){
        cell.hidden = YES;
    }
}
}
[self.tableview reloadData]; 
}

Upvotes: 0

luckymore
luckymore

Reputation: 26

if you want to hide cell B when tapping on a button in cell A (not the cell A itself), I think the good way is just to post a notification when clicking the button, let the UIViewController know it,then remove the datasouce of cellB and reloadData.

Upvotes: 1

Related Questions