易用的可展开TableView,带有动画的插入和删除。代码灵感来源于Apple的示例DateCell
将JNExpandableTableView类复制到您的项目中。
用JNExpandableTableView替换您的UITableView类
要使单元格可展开,只需实现
- (BOOL)tableView:(JNExpandableTableView *)tableView canExpand:(NSIndexPath *)indexPath
{
return YES;
}
由于没有委托拦截,您需要以以下格式返回单元格数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return JNExpandableTableViewNumberOfRowsInSection((JNExpandableTableView *)tableView,section,20);
}
要返回一个展开的单元格,检查indexPath并返回所需的单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.tableView.expandedContentIndexPath isEqual:indexPath])
{
static NSString *CellIdentifier = @"expandedCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
else
{
NSIndexPath * adjustedIndexPath = [self.tableView adjustedIndexPathFromTable:indexPath];
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [NSString stringWithFormat:@"Index: %ld",(long)adjustedIndexPath.row];
return cell;
}
}
JNExpandableTableView是UITableView的一个子类,因此我们没有替换委托和相关拦截。这就是为什么您需要在这个类的一些数据源调用中提供帮助。
MIT许可证(MIT)
版权所有 © 2014 João Nunes
在此特此免费授予任何获得包含在此软件及其相关文档文件(“软件”)副本的任何人(“收到人”)使用该软件的权利,不受限制,包括但不限于使用的权利、复制的权利、修改的权利、合并的权利、出版的权利、分发的权利、再许可的权利,以及/或销售副本的权利,并允许提供给软件的人为此目的进行操作,前提是必须遵守以下条件
以上版权声明和本许可证声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不包括任何明示或暗示的保证,包括但不限于适销性、针对特定目的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或任何其他责任负责,无论此类责任是因合同、侵权或其他行为而引起的,源于、因或与软件或软件的使用或其他方式有关。