cell 展开 点击触发方法 SKSTableView

符修杰
2023-12-01

首先 下载最新的SKSTableView  如果看不懂可以加我QQ 注明来意48564021



- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView = [[SKSTableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-100) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    self.tableView.SKSTableViewDelegate = self;
    
   
    
    [self afnGetRequest];
    
    
    
    
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText = @"正在加载中";
    [self.HUD show:YES];
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"section = %ld row = %ld subRow = %ld ",indexPath.section,indexPath.row,indexPath.subRow);

 
}

//最新版的 会有 这个 did方法  可以选中相应cell
-(void)tableView:(SKSTableView *)tableView didSelectSubRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *str = self.contents[indexPath.section][indexPath.row][indexPath.subRow];

    for (Action *act in self.actArray) {
        if ([act.myName isEqualToString:str]) {
            ActionTypeController *view = [[ActionTypeController alloc]init];
            view.code = act.type;
            [self.navigationController pushViewController:view animated:YES];
        }
    }
    
    NSLog(@"------------%@     ---",str);

}


#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.contents count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.contents[section] count];
}


- (NSInteger)tableView:(SKSTableView *)tableView numberOfSubRowsAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.contents[indexPath.section][indexPath.row] count] - 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SKSTableViewCell";
    
    SKSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell)
        cell = [[SKSTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.textLabel.text = self.contents[indexPath.section][indexPath.row][0];

    cell.expandable = YES;
    
    
    return cell;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForSubRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"UITableViewCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell)
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.textLabel.text = [NSString stringWithFormat:@"%@", self.contents[indexPath.section][indexPath.row][indexPath.subRow]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    
    
    return cell;
}

-(void)afnGetRequest
{
    
    self.array = [NSMutableArray array];
    self.actArray = [NSMutableArray array];
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url_string = @"http://mrobot.pcbaby.com.cn/v2/qzbd/catalog?type=one-two";
    
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"application/x-javascript",@"text/html",nil];
    
    
    [manager GET:url_string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
        //        NSLog(@"使用AFN进行get请求 ===  %@",responseObject);
        //        [[DateHandel shareHandle]dropTable];
        //        [[DateHandel shareHandle]createTable];
        //        [self.array removeAllObjects];
        
        NSMutableArray *array = [NSMutableArray array];
        NSMutableArray *array1 = [NSMutableArray array];
        array = [responseObject objectForKey:@"list"];
        for (NSMutableDictionary *dic in array) {
            self.nameArray = [NSMutableArray array];
            NSMutableArray *arr = [NSMutableArray array];
            arr = [dic objectForKey:@"list"];
            self.myName = [dic objectForKey:@"name"];
            [self.nameArray addObject:self.myName];
//            Action *act1 = [[Action alloc]init];
//            [self.actArray insertObject:act1 atIndex:0];
            for (NSMutableDictionary *listDic in arr) {
                Action *act = [[Action alloc]init];
                act.myName = [listDic objectForKey:@"name"];
                act.type = [listDic objectForKey:@"id"];
                [self.nameArray addObject:act.myName];
                [self.actArray addObject:act];
            }
           
            [array1 addObject:self.nameArray];
        }
        [self.array addObject:array1];
        self.contents = [NSArray arrayWithArray:self.array];
//        NSLog(@"%@",self.actArray);
        [self.tableView reloadData];
        [self.HUD hide:YES];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        [self.HUD hide:YES];
        
    }];
    
}

 类似资料: