'How to open expanded view while pressing Cell of UITableView in iOS?

I have UIWebView. I want to open it just under the UITableView. I have custom cell, with button, or even it can be expand of click of cell (didselectrow).

How can I put UIWebView under Cell and expand it when cell is clicked.

I want also to close it when another cell is clicked, as it will open its respective webview.



Solution 1:[1]

This is an outline of how you can achieve this. The code is not tested, but should be pretty self-explanatory. Let me know if you have questions about it.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _selectedCellIndexPath = indexPath;

    // redraw the visible cells, which will now expand the selected cell
    [_tableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ 
    if([indexPath compare: _selectedCellIndexPath] == NSOrderedSame) {
        return EXPANDED_CELL_HEIGHT;
    } 
    else {
        return NORMAL_CELL_HEIGHT;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     MyCell *cell = …. // get the cell
    if([indexPath compare: _selectedCellIndexPath] == NSOrderedSame) {
        return cell.webView.hidden = NO;
        // update the web view if necessary
    } 
    else {
        return cell.webView.hidden = YES;
    }


    return cell;
}

Solution 2:[2]

this should help you, you need to add web view to your custom cells and update the row height:

https://developer.apple.com/library/ios/samplecode/TableViewUpdates/Introduction/Intro.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TotoroTotoro
Solution 2 ManicMonkOnMac