2023年7月13日发(作者:)
iOS开发之--简单的⼆级联动页⾯1、⽂件⽬录
2、默认选中第0个,然后左侧菜单栏点击切换分类,右侧刷新数据,很简单,这⾥做个记录默认选中代码:- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; = selected == YES ? NO:YES; lor = selected == YES ? olor:rayColor; oundColor = selected == YES ? olor : olor;
// Configure the view for the selected state}3、思路狠简单,解析数据,转数据模型,然后传递相应model即可,具体代码如下:#define Window_Bounds [UIScreen mainScreen].bounds#define Window_H [[UIScreen mainScreen] bounds].#define Window_W [[UIScreen mainScreen] bounds].#import "ViewController.h"#import "leftCell.h"#import "rightCell.h"#import "Model.h"#import "MJExtension.h"#import "NSString+MJExtension.h"#import "NSObject+MJClass.h"#import "subModel.h"@interface ViewController ()
_leftTableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 100, Window_H) style:UITableViewStylePlain]; _te = self; _urce = self; _ooterView = [UIView new]; [ addSubview:_leftTableV];
[_leftTableV selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
_rightTableV = [[UITableView alloc]initWithFrame:CGRectMake(100, 0, Window_W-100, Window_H) style:UITableViewStylePlain]; _te = self; _urce = self; _ooterView = [UIView new]; [ addSubview:_rightTableV];}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (tableView == _leftTableV) { return ; }
return ;}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 50.0f;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (tableView == _leftTableV) { static NSString *left_cellIdentifier = @"leftCell"; leftCell *cell = [_leftTableV dequeueReusableCellWithIdentifier:left_cellIdentifier]; if (!cell) { cell = [[leftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:left_cellIdentifier]; = [NSString stringWithFormat:@"%@",_dataAry[]]; ionStyle = UITableViewCellSelectionStyleNone; }
= y[];
return cell; }else{ static NSString *right_cellIdentifier = @"rightCell"; cell = [_rightTableV dequeueReusableCellWithIdentifier:right_cellIdentifier]; if (!cell) { cell = [[rightCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:right_cellIdentifier]; }
el = egories[];
return cell; }}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (tableView == _leftTableV) {
[egories removeAllObjects];
//当前选中的索引 _selIndexPath = indexPath;
[self setSubData];
[_rightTableV reloadData]; }}-(NSMutableArray *)subcategories{ if (!_subcategories) { //默认选中展⽰数据 _subcategories = [NSMutableArray array]; [self setSubData]; } return _subcategories;}-(void)setSubData{ Model *model = [[Model alloc]init]; model = y[_]; NSMutableArray *subAry = [NSMutableArray arrayWithArray:egories]; for (NSDictionary *dict in subAry) { subModel *model = [subModel mj_objectWithKeyValues:dict]; [_subcategories addObject:model]; }}@end
效果如下:
仅做记录!
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689263913a226396.html
评论列表(0条)