简体   繁体   English

在iOS中按UITableView的单元格时如何打开展开的视图?

[英]How to open expanded view while pressing Cell of UITableView in iOS?

I have UIWebView. 我有UIWebView。 I want to open it just under the UITableView. 我想在UITableView下打开它。 I have custom cell, with button, or even it can be expand of click of cell (didselectrow). 我有自定义单元格,带有按钮,甚至可以扩展单元格的点击范围(didselectrow)。

How can I put UIWebView under Cell and expand it when cell is clicked. 我如何将UIWebView放在Cell下并单击它时将其展开。

I want also to close it when another cell is clicked, as it will open its respective webview. 我也想在单击另一个单元格时将其关闭,因为它将打开其各自的Web视图。

Thanks 谢谢

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;
}

this should help you, you need to add web view to your custom cells and update the row height: 这对您有帮助,您需要将Web视图添加到自定义单元格并更新行高:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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