根据节标题筛选UITableView的整个部分
我正在试图找出解决这个问题的最佳方法。 我有一个UITableView,其中可能有X个部分。 我也有一个button,产生一个自定义UIPickerView的显示每个部分的标题(我从数组中得到这些值,而不是UITableView,因为我无法弄清楚如何)的自定义UIPickerView的popup式窗口。
当他们select一个选项时,我想要隐藏UITableView期望的所有部分,显然,所选部分的标题为一个部分。
我想知道是否可以遍历所有的部分,看看它的标题,如果它不符合select,隐藏它? 可能值得注意的是,再也不会有超过10个部分,每个部分都有几个单元,所以我不知道[table updateTable]或[table reloadData]是否更好。
我的尝试:
//Filter out the notes that should display -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ //self.notesTable.dataSource = [myArrayOfDictionaries objectAtIndex:row]; //[self.notesTable reloadData]; this did not work for (int section = 0; section < [notesTable numberOfSections]; section++){ //find sections that don't match pickerview selection NSLog@("%@",[notesTable headerViewForSection:row);//return null? } }
你可以请你的UITableView.delegate
和UITableView.dataSource
方法的代码?
你想要做这样的事情:
- 维护一个指向allData的@property,并维护另一个指向currentData的@property
- 用户select一个部分
- 你从allData中获取sectionData,将这个sectionData设置为你的currentData
- 在
tableView
上调用reloadData
- 确保你的
delegate
和dataSource
方法引用currentData
@property
它看起来像这样不适合你的原因是因为你正在设置UITableView
的dataSource = currentData
,这是不正确的。 应始终将DataSource
设置为符合此协议的类(可能是您的UIViewController
)。