[英]Expandable UITableView cells showing datas
在這種情況下,您甚至不需要使用擴展/手風琴。 這是解決該問題的方法。 假設正常情況下的單元格大小為40,特別單擊時的單元格大小為100。在heightForRowAtIndexPath中,您可以檢查選擇了哪個單元格並返回更高的高度
if(selectedRow == indexPath.row) {
return 100;
} else {
return 40;
}
然后,您可以在didSelectRowAtIndexPath或clickEvent方法中進行操作
[self.tableView beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem: selectedRow inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
因此,它將是您的單元格全部呈現的內容,但是根據高度,您將隱藏或顯示內容。
使用輸入源更新答案
ViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(selectedIndex == indexPath.row)
return 100;
else
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
customCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSDictionary *matches = self.dataArray[indexPath.row];
cell.matchName.text = [matches objectForKey@"MatchName"];
if() {
cell.heightConstraintSecondView.constant = 0;
} else {
cell.heightConstraintSecondView.constant = 59;
cell.team1.text = [matches objectForKey@"Team1"];
cell.team2.text = [matches objectForKey@"Team2"];
cell.score.text = [matches objectForKey@"Score"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndex = indexPath.row;
[self.tableView beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
}
較干凈的方法是創建2個具有不同標識符的單元格,然后在運行時單擊該單元格進行更改。 檢查以下問題: iOS中的UITableView中的下拉列表
您可以為此目的使用HVtableview,請嘗試此鏈接https://github.com/xerxes235/HVTableView
嘗試以下方法之一:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.