Expanding table view cells disappearing

前端 未结 7 1431
逝去的感伤
逝去的感伤 2021-02-12 23:36

I have cells that expand by changing their height with a setExpanded: method call.

I then call reloadRowsAtIndexPaths: to refresh the cells.

The problem is the c

7条回答
  •  生来不讨喜
    2021-02-13 00:11

    @Javy,

    Thanks for your question. I was developing table with similar behaviour: there are text views (UITextView) in my table view cells (UITableViewCell) that are :

    1. expanding if new line is required to display text without scrolling, or
    2. collapsing if new line was removed

    So I found the same problem. In iOS 5.x when I was starting to type text it suddenly was becoming invisible. But in iOS 4.x everything works fine.

    I have found the solution and it works well for me.

    Solution: Just try to replace your animation type UITableViewRowAnimationAutomatic with UITableViewRowAnimationNone when reloading the particular cell.

    Some additional code: reload both cell in one moment:

        NSMutableArray *indexes = [NSMutableArray arrayWithCapacity:2];
        // collapse previous cell
        if( previousCell != nil && [previousCell expandable] )
        {
            if( [previousCell expanded] ) [previousCell setExpanded:NO];
            [indexes addObject:previousIndexPath_];
        }
    
        // expand new cell
        if( [cell expandable] )
        {
            [cell setExpanded:YES];
            [indexes addObject:indexPath];
        }
    
        [tableView reloadRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationNone];
    

    Hope it will help you.

提交回复
热议问题