MultilevelMenu.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. //
  2. // MultilevelMenu.m
  3. // MultilevelMenu
  4. //
  5. // Created by Kingson on 2021/4/25.
  6. //
  7. #import "MultilevelMenu.h"
  8. #import "MultilevelTableViewCell.h"
  9. #import "ProductCateFilteHeaderView.h"
  10. #import "CollectviewChooseCell.h"
  11. #import "NSString+hAdd.h"
  12. #import <Masonry/Masonry.h>
  13. #import "NYVideoListCell.h"
  14. #define kCellRightLineTag 100
  15. #define ItemHeight 70
  16. #define kMultilevelCollectionHeader @"CollectionHeader"//CollectionHeader
  17. #define kScreenWidth [UIScreen mainScreen].bounds.size.width
  18. #define kScreenHeight [UIScreen mainScreen].bounds.size.height
  19. #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  20. #define MAX3(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
  21. static NSString *HeaderId = @"HeaderId";
  22. static NSString *CellId = @"CellId";
  23. @interface MultilevelMenu()
  24. @property(strong,nonatomic ) UITableView * leftTablew;
  25. //@property(strong,nonatomic ) UICollectionView * rightCollection;
  26. @property(assign,nonatomic) BOOL isReturnLastOffset;
  27. //可变数组记录头视图的按钮
  28. @property(nonatomic,strong) NSMutableArray *headerBtnArr;
  29. @end
  30. @implementation MultilevelMenu{
  31. UICollectionReusableView *headReusableview;
  32. }
  33. - (NSMutableArray *)headerBtnArr{
  34. if (!_headerBtnArr) {
  35. _headerBtnArr = [NSMutableArray array];
  36. }
  37. return _headerBtnArr;
  38. }
  39. -(instancetype)initWithFrame:(CGRect)frame WithData:(NSArray *)data withSelectIndex:(void (^)(NSInteger, NSInteger, id))selectIndex
  40. {
  41. self=[super initWithFrame:frame];
  42. if (self) {
  43. if (data.count==0) {
  44. return nil;
  45. }
  46. _block=selectIndex;
  47. self.leftSelectColor=[UIColor blackColor];
  48. self.leftSelectBgColor=[UIColor whiteColor];
  49. self.leftBgColor=UIColorFromRGB(0xF3F4F6);
  50. self.leftSeparatorColor=UIColorFromRGB(0xE5E5E5);
  51. self.leftUnSelectBgColor=UIColorFromRGB(0xF3F4F6);
  52. self.leftUnSelectColor=[UIColor blackColor];
  53. _selectIndex=0;
  54. _allData=data;
  55. _choosedArr = [[NSMutableArray alloc] initWithCapacity:0];
  56. /**
  57. 左边的视图
  58. */
  59. self.leftTablew=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, kLeftWidth, frame.size.height)];
  60. self.leftTablew.dataSource=self;
  61. self.leftTablew.delegate=self;
  62. self.leftTablew.tableFooterView=[[UIView alloc] init];
  63. [self addSubview:self.leftTablew];
  64. self.leftTablew.backgroundColor=self.leftBgColor;
  65. if ([self.leftTablew respondsToSelector:@selector(setLayoutMargins:)]) {
  66. self.leftTablew.layoutMargins=UIEdgeInsetsZero;
  67. }
  68. if ([self.leftTablew respondsToSelector:@selector(setSeparatorInset:)]) {
  69. self.leftTablew.separatorInset=UIEdgeInsetsZero;
  70. }
  71. self.leftTablew.separatorColor=self.leftSeparatorColor;
  72. self.leftTablew.estimatedRowHeight = 70;
  73. self.leftTablew.rowHeight = UITableViewAutomaticDimension;
  74. /**
  75. 右边的视图
  76. */
  77. UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
  78. self.rightCollection=[[UICollectionView alloc] initWithFrame:CGRectMake(kLeftWidth,0,kScreenWidth-kLeftWidth,frame.size.height) collectionViewLayout:flowLayout];
  79. self.rightCollection.delegate=self;
  80. self.rightCollection.dataSource=self;
  81. UINib *header=[UINib nibWithNibName:kMultilevelCollectionHeader bundle:nil];
  82. [self.rightCollection registerNib:header forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kMultilevelCollectionHeader];
  83. [self.rightCollection registerClass:[ProductCateFilteHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderId];
  84. [self.rightCollection registerClass:[CollectviewChooseCell class] forCellWithReuseIdentifier:CellId];
  85. [self.rightCollection registerNib:[UINib nibWithNibName:@"NYVideoListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"NYVideoListCell"];
  86. self.rightCollection.showsVerticalScrollIndicator = NO;
  87. [self addSubview:self.rightCollection];
  88. self.isReturnLastOffset=YES;
  89. self.rightCollection.backgroundColor=self.leftSelectBgColor;
  90. self.backgroundColor=self.leftSelectBgColor;
  91. }
  92. return self;
  93. }
  94. -(void)setNeedToScorllerIndex:(NSInteger)needToScorllerIndex{
  95. /**
  96. * 滑动到 指定行数
  97. */
  98. [self.leftTablew selectRowAtIndexPath:[NSIndexPath indexPathForRow:needToScorllerIndex inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
  99. _selectIndex=needToScorllerIndex;
  100. [self.rightCollection reloadData];
  101. _needToScorllerIndex=needToScorllerIndex;
  102. }
  103. -(void)setLeftBgColor:(UIColor *)leftBgColor{
  104. _leftBgColor=leftBgColor;
  105. self.leftTablew.backgroundColor=leftBgColor;
  106. }
  107. -(void)setLeftSelectBgColor:(UIColor *)leftSelectBgColor{
  108. _leftSelectBgColor=leftSelectBgColor;
  109. self.rightCollection.backgroundColor=leftSelectBgColor;
  110. self.backgroundColor=leftSelectBgColor;
  111. }
  112. -(void)setLeftSeparatorColor:(UIColor *)leftSeparatorColor{
  113. _leftSeparatorColor=leftSeparatorColor;
  114. self.leftTablew.separatorColor=leftSeparatorColor;
  115. }
  116. -(void)reloadData{
  117. [self.leftTablew reloadData];
  118. [self.rightCollection reloadData];
  119. }
  120. -(void)setLeftTablewCellSelected:(BOOL)selected withCell:(MultilevelTableViewCell*)cell
  121. {
  122. UILabel * line=(UILabel*)[cell viewWithTag:kCellRightLineTag];
  123. if (selected) {
  124. line.backgroundColor=cell.backgroundColor;
  125. cell.titile.textColor=self.leftSelectColor;
  126. cell.backgroundColor=self.leftSelectBgColor;
  127. }
  128. else{
  129. cell.titile.textColor=self.leftUnSelectColor;
  130. cell.backgroundColor=self.leftUnSelectBgColor;
  131. line.backgroundColor=_leftTablew.separatorColor;
  132. }
  133. }
  134. #pragma mark---左边的tablew 代理
  135. #pragma mark--deleagte
  136. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  137. return 1;
  138. }
  139. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  140. return self.allData.count;
  141. }
  142. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  143. static NSString * Identifier=@"MultilevelTableViewCell";
  144. MultilevelTableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:Identifier];
  145. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  146. if (!cell) {
  147. cell=[[NSBundle mainBundle] loadNibNamed:@"MultilevelTableViewCell" owner:self options:nil][0];
  148. UILabel * label=[[UILabel alloc] initWithFrame:CGRectMake(kLeftWidth-0.5, 0, 0.5, 44)];
  149. label.backgroundColor = tableView.separatorColor;
  150. [cell addSubview:label];
  151. label.numberOfLines = 0;
  152. label.tag = kCellRightLineTag;
  153. }
  154. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  155. rightMeun * title=self.allData[indexPath.row];
  156. cell.titile.text = title.meunName;
  157. cell.titile.font = [UIFont systemFontOfSize:13];
  158. if (indexPath.row==self.selectIndex) {
  159. [self setLeftTablewCellSelected:YES withCell:cell];
  160. }else{
  161. [self setLeftTablewCellSelected:NO withCell:cell];
  162. }
  163. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  164. cell.layoutMargins=UIEdgeInsetsZero;
  165. }
  166. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  167. cell.separatorInset=UIEdgeInsetsZero;
  168. }
  169. return cell;
  170. }
  171. //-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  172. // return 44;
  173. //}
  174. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  175. MultilevelTableViewCell * cell=(MultilevelTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
  176. _selectIndex = indexPath.row;
  177. [self setLeftTablewCellSelected:YES withCell:cell];
  178. rightMeun *title=self.allData[indexPath.row];
  179. [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
  180. self.isReturnLastOffset=NO;
  181. [self.rightCollection reloadData];
  182. if (self.isRecordLastScroll) {
  183. [self.rightCollection scrollRectToVisible:CGRectMake(0, title.offsetScorller, self.rightCollection.frame.size.width, self.rightCollection.frame.size.height) animated:self.isRecordLastScrollAnimated];
  184. }
  185. else{
  186. [self.rightCollection scrollRectToVisible:CGRectMake(0, 0, self.rightCollection.frame.size.width, self.rightCollection.frame.size.height) animated:self.isRecordLastScrollAnimated];
  187. }
  188. }
  189. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
  190. MultilevelTableViewCell * cell=(MultilevelTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
  191. [self setLeftTablewCellSelected:NO withCell:cell];
  192. cell.backgroundColor = self.leftUnSelectBgColor;
  193. }
  194. #pragma mark---imageCollectionView--------------------------
  195. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  196. if (self.allData.count==0) {
  197. return 0;
  198. }
  199. rightMeun * title=self.allData[self.selectIndex];
  200. return title.nextArray.count;
  201. }
  202. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  203. rightMeun * title=self.allData[self.selectIndex];
  204. if (title.nextArray.count>0) {
  205. rightMeun *sub=title.nextArray[section];
  206. if (sub.nextArray.count==0)//没有下一级
  207. {
  208. return 1;
  209. }
  210. else
  211. return sub.nextArray.count;
  212. }else{
  213. return title.nextArray.count;
  214. }
  215. }
  216. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  217. CollectviewChooseCell * cell = (CollectviewChooseCell *)[collectionView cellForItemAtIndexPath:indexPath];
  218. rightMeun *title = self.allData[self.selectIndex];
  219. //获取到当前选择的item
  220. rightMeun *menu;
  221. menu = title.nextArray[indexPath.section];
  222. _chooseBlock(menu.meunName,_choosedArr,indexPath);
  223. }
  224. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  225. rightMeun * title = self.allData[self.selectIndex];
  226. NSArray *list;
  227. rightMeun * meun;
  228. meun=title.nextArray[indexPath.section];
  229. if (meun.nextArray.count > 0) {
  230. meun = title.nextArray[indexPath.section];
  231. list = meun.nextArray;
  232. meun = list[indexPath.row];
  233. }
  234. NSString *reuseIdetify = @"NYVideoListCell";
  235. NYVideoListCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdetify forIndexPath:indexPath];
  236. cell.backgroundColor = [UIColor clearColor];
  237. if(meun.model){
  238. [cell reloadData:meun.model];
  239. }
  240. return cell;
  241. }
  242. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  243. NSString *reuseIdentifier;
  244. if ([kind isEqualToString:UICollectionElementKindSectionFooter]){
  245. reuseIdentifier = @"footer";
  246. }else{
  247. reuseIdentifier = kMultilevelCollectionHeader;
  248. }
  249. rightMeun *title = self.allData[self.selectIndex];
  250. if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
  251. ProductCateFilteHeaderView *headReusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderId forIndexPath:indexPath];
  252. headReusableview.backgroundColor = [UIColor whiteColor];
  253. //取消复用
  254. for (UIView *view in headReusableview.subviews) {
  255. [view removeFromSuperview];
  256. }
  257. UILabel *HeaderTitleLab = [[UILabel alloc] init];
  258. [HeaderTitleLab setFont:[UIFont systemFontOfSize:15.0f]];
  259. HeaderTitleLab.numberOfLines = 0;
  260. NSArray *menuArr = [NSArray array];
  261. // HeaderTitleLab.text = @"全选";
  262. if (title.nextArray.count > 0) {
  263. rightMeun * meun;
  264. meun=title.nextArray[indexPath.section];
  265. HeaderTitleLab.text = meun.meunName;
  266. menuArr = [meun.nextArray copy];
  267. }else{
  268. HeaderTitleLab.text = @"暂无";
  269. }
  270. [headReusableview addSubview:HeaderTitleLab];
  271. [HeaderTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  272. make.left.equalTo(headReusableview.mas_left).offset(15);
  273. make.top.equalTo(headReusableview.mas_top).offset(0);
  274. make.height.mas_equalTo(headReusableview.mas_height);
  275. }];
  276. UIButton *chooseIcon = [UIButton buttonWithType:UIButtonTypeCustom];
  277. //判断当前的全选状态
  278. [chooseIcon setImage:[UIImage imageNamed:@"table_UnSelect"] forState:UIControlStateNormal];
  279. [chooseIcon setImage:[UIImage imageNamed:@"table_Selected"] forState:UIControlStateSelected];
  280. chooseIcon.tag = indexPath.section;
  281. [chooseIcon addTarget:self action:@selector(ChooseAllClick:) forControlEvents:UIControlEventTouchUpInside];
  282. [headReusableview addSubview:chooseIcon];
  283. [chooseIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  284. make.left.equalTo(HeaderTitleLab.mas_right).offset(10);
  285. make.right.equalTo(headReusableview.mas_right).offset(-15);
  286. make.top.equalTo(headReusableview.mas_top);
  287. make.height.mas_equalTo(headReusableview.mas_height);
  288. make.width.mas_equalTo(50);
  289. }];
  290. BOOL isContain2 = true;
  291. // //找出相同的数组
  292. if (_choosedArr.count > 0) {
  293. NSMutableArray *testArr1 = [NSMutableArray array];
  294. for (rightMeun *ocl in _choosedArr) {
  295. for (rightMeun *ocl2 in menuArr) {
  296. if ([ocl.meunName isEqualToString:ocl2.meunName]) {
  297. [testArr1 addObject:ocl];
  298. }
  299. }
  300. }
  301. [testArr1 sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
  302. rightMeun *key1 = obj1;
  303. rightMeun *key2 = obj2;
  304. NSInteger key1Integer = [key1.ID integerValue];
  305. NSInteger key2Integer = [key2.ID integerValue];
  306. if (key1Integer < key2Integer) {
  307. return NSOrderedAscending;
  308. }
  309. if (key1Integer > key2Integer) {
  310. return NSOrderedDescending;
  311. }
  312. return NSOrderedSame;;
  313. }];
  314. if (testArr1.count == 0 && menuArr.count == 0) {
  315. isContain2 = false;
  316. }else{
  317. isContain2 = [[testArr1 copy] isEqual:menuArr];
  318. }
  319. }else{
  320. isContain2 = false;
  321. }
  322. if (isContain2) {
  323. [chooseIcon setSelected:YES];
  324. }else{
  325. [chooseIcon setSelected:NO];
  326. }
  327. return headReusableview;
  328. }
  329. else if ([kind isEqualToString:UICollectionElementKindSectionFooter]){
  330. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind :kind withReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
  331. UILabel *label = (UILabel *)[view viewWithTag:1];
  332. label.font = [UIFont systemFontOfSize:15];
  333. label.textColor = UIColorFromRGB(0x686868);
  334. view.backgroundColor = [UIColor lightGrayColor];
  335. label.text = [NSString stringWithFormat:@"这是footer:%ld",(long)indexPath.section];
  336. return view;
  337. }else{
  338. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind :kind withReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
  339. return view;
  340. }
  341. }
  342. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  343. // return CGSizeMake(60, 90);
  344. //根据文本计算出item的高度
  345. rightMeun * title = self.allData[self.selectIndex];
  346. NSArray *list;
  347. rightMeun * meun;
  348. meun=title.nextArray[indexPath.section];
  349. if (meun.nextArray.count > 0) {
  350. meun = title.nextArray[indexPath.section];
  351. list = meun.nextArray;
  352. meun = list[indexPath.row];
  353. }
  354. NSInteger rowC = indexPath.row;
  355. CGFloat labelWidth = (kScreenWidth - kLeftWidth);
  356. CGFloat itemHeight = RQ_FIT_HORIZONTAL(82);
  357. return CGSizeMake(labelWidth,itemHeight);
  358. }
  359. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  360. return UIEdgeInsetsMake(10, 10, 10, 10);
  361. }
  362. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  363. CGSize size = {kScreenWidth,0.1};
  364. return size;
  365. }
  366. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  367. //行间距
  368. return 10;
  369. }
  370. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  371. return 10;
  372. }
  373. #pragma mark---记录滑动的坐标
  374. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  375. {
  376. if ([scrollView isEqual:self.rightCollection]) {
  377. self.isReturnLastOffset=YES;
  378. }
  379. }
  380. -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  381. {
  382. if ([scrollView isEqual:self.rightCollection]) {
  383. rightMeun * title=self.allData[self.selectIndex];
  384. title.offsetScorller=scrollView.contentOffset.y;
  385. self.isReturnLastOffset=NO;
  386. }
  387. }
  388. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  389. if ([scrollView isEqual:self.rightCollection]) {
  390. rightMeun * title=self.allData[self.selectIndex];
  391. title.offsetScorller=scrollView.contentOffset.y;
  392. self.isReturnLastOffset=NO;
  393. }
  394. }
  395. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  396. if ([scrollView isEqual:self.rightCollection] && self.isReturnLastOffset) {
  397. rightMeun * title=self.allData[self.selectIndex];
  398. title.offsetScorller=scrollView.contentOffset.y;
  399. }
  400. }
  401. -(void)ChooseAllClick:(UIButton *)button{
  402. NSInteger sectionIndex = button.tag;
  403. BOOL selectType = button.isSelected;
  404. rightMeun *title = self.allData[self.selectIndex];
  405. //获取到当前选择的item
  406. rightMeun *menu;
  407. menu = title.nextArray[sectionIndex];
  408. NSArray *selectArr = menu.nextArray;
  409. if (selectArr.count > 0) {
  410. //判断当前是全选还是取消全选状态
  411. if (_choosedArr.count == 0) {
  412. //全选
  413. if (!selectType) {
  414. //选中
  415. [_choosedArr addObjectsFromArray:selectArr];
  416. }
  417. }else{
  418. if (selectType) {
  419. //移除数组内数据
  420. [_choosedArr removeObjectsInArray:selectArr];
  421. }else{
  422. //添加到数组内
  423. [_choosedArr removeObjectsInArray:selectArr];
  424. [_choosedArr addObjectsFromArray:selectArr];
  425. }
  426. }
  427. }
  428. //记录选择的数据 并更新视图
  429. _ifAllSelecteSwitch = YES;
  430. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:button.tag];
  431. NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:indexPath.section];
  432. [_rightCollection reloadSections:indexSet];
  433. // [_rightCollection reloadData];
  434. _chooseBlock(@"All",_choosedArr,indexPath);
  435. }
  436. #pragma mark--Tools
  437. -(void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)delay{
  438. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));
  439. dispatch_after(popTime, dispatch_get_main_queue(), block);
  440. }
  441. @end
  442. @implementation rightMeun
  443. - (BOOL)isEqual:(rightMeun *)object{
  444. return [self isEualToRightMeun:object];
  445. }
  446. -(BOOL)isEualToRightMeun:(rightMeun *)rightMenu{
  447. if (![rightMenu isKindOfClass:self.class]) {
  448. return NO;
  449. }
  450. BOOL result = ([self.meunName isEqualToString:rightMenu.meunName]);
  451. if (result == NO) {
  452. return NO;
  453. }else{
  454. return YES;
  455. }
  456. }
  457. @end