我有一些按年份编制的体育比赛,每场比赛我都有最终结果,比赛日期和得分手。展开数据的可展开UITableView单元格
我展示这些比赛在“表视图”,像这样:
所以想什么,我实现的是:在一个小区,当点击,显示比赛细节如图所示。
我也发现了一些图书馆来实现手风琴/可扩展的风格,但没有人做这项工作。他们只是展开细胞并展示另一个细胞。
我有一些按年份编制的体育比赛,每场比赛我都有最终结果,比赛日期和得分手。展开数据的可展开UITableView单元格
我展示这些比赛在“表视图”,像这样:
所以想什么,我实现的是:在一个小区,当点击,显示比赛细节如图所示。
我也发现了一些图书馆来实现手风琴/可扩展的风格,但没有人做这项工作。他们只是展开细胞并展示另一个细胞。
在这种情况下,您甚至不需要使用可扩展/手风琴。这是你如何解决这个问题。让我们说,你的细胞大小时正常为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 [email protected]"MatchName"];
if() {
cell.heightConstraintSecondView.constant = 0;
} else {
cell.heightConstraintSecondView.constant = 59;
cell.team1.text = [matches [email protected]"Team1"];
cell.team2.text = [matches [email protected]"Team2"];
cell.score.text = [matches [email protected]"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];
}
}
不错!那么我应该在哪里添加匹配信息? (比如'team1 [selected_cell],team2 [selected_cell]'等等?在'beginupdates'和'endUpdates'之间? – fabersky
你只需要重新加载选中的单元格并在heightforRow中改变它的高度......你是否在动态创建你的单元格?你需要用所有元素创建你的单元格,只需在取消选择时更改其高度以显示或隐藏匹配详细信息 –
我已将所有匹配详细信息保存在数组中,因此基本上所有单元格都是相同的当我选择单元格1时,它会显示细胞的细节(匹配),当我选择cell2时它会显示match2细节,等等...... – fabersky
的清洁方法是创建2个细胞不同的标识符,并在运行时更改它,当您单击该单元格。检查这个问题:Drop-Down List in UITableView in iOS
可以用户HVtableview为此,试试这个链接 https://github.com/xerxes235/HVTableView
尝试其中之一:
解决此问题的其他方法http://stackoverflow.com/questions/29678471/expandi ng-and-collapsing-uitableviewcells-with-datepicker/34703276#34703276 – DogCoffee
非常有帮助!感谢@DogCoffee! – fabersky
[iOS中的UITableView中的下拉列表]的可能重复(http://stackoverflow.com/questions/33186659/drop-down-list-in-uitableview-in-ios) – Rick