繁体   English   中英

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

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

我有UIWebView。 我想在UITableView下打开它。 我有自定义单元格,带有按钮,甚至可以扩展单元格的点击范围(didselectrow)。

我如何将UIWebView放在Cell下并单击它时将其展开。

我也想在单击另一个单元格时将其关闭,因为它将打开其各自的Web视图。

谢谢

这是如何实现此目的的概述。 该代码未经测试,但是应该很容易解释。 如果您有任何疑问,请告诉我。

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

这对您有帮助,您需要将Web视图添加到自定义单元格并更新行高:

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