Ios 类似appStore上的tableView实现
以前 之后 基本上我的观点是我有customTableViewCell,它在最右边有一个按钮(与image1“显示版本历史记录”相同)。单击该按钮时,我希望添加customTableViewCells下的动态数量的subviewCellIos 类似appStore上的tableView实现,ios,uitableview,ios7,Ios,Uitableview,Ios7,以前 之后 基本上我的观点是我有customTableViewCell,它在最右边有一个按钮(与image1“显示版本历史记录”相同)。单击该按钮时,我希望添加customTableViewCells下的动态数量的subviewCell 我的问题是,这是如何实施的?有什么库可以参考吗?看看这些表视图实现 我希望您没有搜索它: 让我们看看这些链接: 这很容易 您希望跟踪区段是否展开。为此使用实例变量(或属性) 如果未展开,则在可展开部分的表格视图:numberofrows
我的问题是,这是如何实施的?有什么库可以参考吗?看看这些表视图实现
我希望您没有搜索它: 让我们看看这些链接:
-
这很容易
- 您希望跟踪区段是否展开。为此使用实例变量(或属性)
- 如果未展开,则在可展开部分的
中返回1表格视图:numberofrowsinssection:
- 如果展开,则返回1+在
t:numberOfRowsInSection:
- 在
中,点击第一个单元格时切换展开状态,插入或删除展开的行李>tableView:didSelectRowAtIndexPath:
@interface MBMasterViewController () {
BOOL firstSectionExpanded;
}
@end
@implementation MBMasterViewController
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger count = 1;
if (section == 0 && firstSectionExpanded) { count = 3; }
return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
if (indexPath.row == 0) {
cell.textLabel.text = [NSString stringWithFormat:@"Section %ld", (long)indexPath.section];
}
else {
cell.textLabel.text = [NSString stringWithFormat:@"Sub Cell %ld", (long)indexPath.row];
}
return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row != 0) {
// don't select sub cells
return nil;
}
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *cells = @[ [NSIndexPath indexPathForRow:1 inSection:indexPath.section],
[NSIndexPath indexPathForRow:2 inSection:indexPath.section]];
NSArray *cellsToDelete;
NSArray *cellsToInsert;
if (indexPath.section == 0) {
if (firstSectionExpanded) {
cellsToDelete = cells;
}
else {
cellsToInsert = cells;
}
firstSectionExpanded = !firstSectionExpanded;
}
if (cellsToDelete) {
[tableView deleteRowsAtIndexPaths:cellsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
}
if (cellsToInsert) {
[tableView insertRowsAtIndexPaths:cellsToInsert withRowAnimation:UITableViewRowAnimationAutomatic];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
非常感谢。我会检查所有的……哪种方法最好?你是怎么解决的?