我有一个 TableViewController,可以随时添加或删除部分和行。每个部分的标题都是一个 UITableViewHeaderFooterView,其中添加了一个按钮。
当一个按钮被触摸时,你如何确定触摸按钮所在部分的索引?
先决条件
有一个模型对象驱动 tableview。该模型有一个属性返回一个表示部分数的数组。数组中的每个对象代表一行。
要求
实现不得依赖于状态或模型信息的重复。
行和节将通过 tableview 动画插入和删除。 理想情况下,不会调用 Tableview reloadData 进行更新。
最佳答案
定义 UIViews
的实例变量 NSMutableArray
(您的部分页脚)。这将作为节页眉/页脚的数据源:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *buttonView = [self.sectionArray objectAtIndex:section];
return buttonView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.sectionArray count];
}
- (void)didPressSectionButton:(id)sender
{
int section = [self.sectionArray indexOfObject:sender];
}
这只是一个基本示例,您可以使用 NSDictionary 为行和部分的整个 UITableView 提供动力。使用 KV 对。
关于ios - 根据动态 TableView 中节标题中控件的操作确定节的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19570543/