1.一个xib的UIView中包含两个tableView
@interface HMDropdownView ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView*leftTableView;
@property (weak, nonatomic) IBOutlet UITableView*rightTableView;
/** 选中的左边分类模型 */
@property (nonatomic,strong) HMCategoryModel*selectLeftCategoryModel;
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
//点击左边时, 才需要记录
if (tableView == self.leftTableView) {
//1. 记录左边选中的模型
self.selectLeftCategoryModel = self.categoryArray[indexPath.row];
//2. 刷新右边表格
[self.rightTableView reloadData];
}
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
//根据是左边的tableView还是右边的tableView来判断是哪个表格
if (tableView == self.leftTableView) {
return self.categorys.count;
} else{
WRCategoryModel *model = self.categorys[self.selectedIdx];
return model.subcategories.count;
}
}