2017-02-10 53 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