简体   繁体   中英

Modify cell on didSelectRowAtIndexPath in UITableView

I have 2 views on a table view cell view1 and view2 and what i want to do is when i tap on a cell i want that view1 to be hidden and view2 to be displayed (at the beginning view1 was displayed and view2 was hidden), I used tags for view view1 = 102 and view2 = 103, for some reason I which i can not figure, the view1 is hidden but the view2 is not displayed.

here is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];


    UIView * view1 = (UIView *)[cell viewWithTag:102];
    UIView * view2 = (UIView *)[cell viewWithTag:103];

    [view1 setHidden:YES];
    [view2 setHidden:NO];


    NSLog(@"View 2 is : %hhd",view2.hidden);


}

storyBoard 在此处输入图片说明

simulator

在此处输入图片说明

instead of

cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

use

cell = [tableView cellForRowAtIndexPath:indexPath];

Because dequeueReusableCellWithIdentifier: forIndexPath: will return a currently unused table cell that is currently not visible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM