2017-02-10 51 views
0

我想在UITableViewCell里面显示子单元格。我有两个包含groupname和groupid的数组。我能够通过使用下面的代码在具有自定义TableViewCell的tableview中显示组名。在UITableViewCell里面显示子单元

NSArray *groupIdArr; 
    NSArray *groupNameArr; 

groupNameArr (
    ANTISERA, 
    CLIA, 
    COAGULATION, 
    CONFIRMATORY, 
    ELISA, 
    IMMUNOLOGY, 
    MISC, 
    RAPID 
) 

groupIdArr (
    20, 
    21, 
    22, 
    23, 
    19, 
    31, 
    29, 
    18 
) 


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



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"ProductGroupTableViewCell"; 

    ProductGroupTableViewCell *cell = (ProductGroupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ProductGroupTableViewCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.productGroupNameLbl.text = [groupNameArr objectAtIndex:indexPath.row]; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     NSString *saveGroupId = [groupIdArr objectAtIndex:indexPath.row]; 

     [[NSUserDefaults standardUserDefaults] setObject:saveGroupId forKey:@"SavedGroupId"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UIViewController *productListVC = [storyboard instantiateViewControllerWithIdentifier:@"ProductsListViewController"]; 
    [self.navigationController pushViewController:productListVC animated:YES]; 


} 

enter image description here

当用户点击TableViewCell用户可以看到与所选的groupid像下面,他可以选择的产品的产品列表。

enter image description here

选择产品的用户后,将完成按按钮返回到上一个视图,在那里他可以看到下面的组名所选的产品。我在NSMutableArray中将选定的产品名称带到之前的视图。但我无法弄清楚如何显示下面的输出。

我试了很多找到解决方案,但没有运气。任何帮助将非常感激。

enter image description here

回答

0

可以使用的UIView用于显示内部电池的子电池。以编程方式创建UIView。无论何时需要,在单元格内添加此视图并重新加载该特定单元格并根据需要的高度更改高度...并且您可以轻松完成任务。

0

请检查这个演示,你会发现你的解决方案。

SideMenu Demo

+0

下载这个,你必须更改位代码。你有了你的愿望结果。只为你开发演示。让我知道你是否需要任何帮助。 – PSS