[英]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.