2015-10-01 39 views
-1

我有字典结构,我想安排在UITableView上述词典以这样的方式是如下创建可扩展的UITableView和正常的UITableViewCell中的UITableView

{ 
    data =  { 
     "parent_category_list" =   (
         { 
       "cat_master_id" = 127; 
       "cat_name" = Accessories; 
       "cul_name" = en; 
       "culture_category_id" = 127; 
       "local_id" = 283; 
       "parent_id" = 0; 
       "pms_id" = 127; 
       slug = "accessories-1"; 
      }, 
         { 
       "cat_master_id" = 323; 
       "cat_name" = "Acrylic Products"; 
       "cul_name" = en; 
       "culture_category_id" = 323; 
       "local_id" = 247; 
       "parent_id" = 0; 
       "pms_id" = 323; 
       slug = "acrylic-products-1"; 
      },{ 
       "cat_master_id" = 252; 
       "cat_name" = Coolers; 
       child =     (
             { 
         "cat_master_id" = 1200; 
         "cat_name" = "Drink Ware"; 
         "cul_name" = en; 
         "culture_category_id" = 2031; 
         "local_id" = 284; 
         "parent_id" = 250; 
         "pms_id" = 1200; 
         slug = "drink-ware-1"; 
        } 
       ); 
} 

,如果字典里子类。子字典,那么单元格应该是可扩展的,或者如果没有子类别,那么应该是正常单元格。哪些应该是可点击的。 我该如何设置?

+2

你至少应该尝试解决问题,并解释你花了这么步骤,我们可以引导你走向解。现在你期望社区为你做你的功课:) –

+0

我已经做了你想做的事情,我做得很好。 –

+0

我会建议你使用Model类来完成它,并且父类有一组子类 –

回答

0

我在这里把所有的字典到一个名为数组“ARR”

arr=[data objectForKey:@"parent_category_list"]; 

并实现了基于字典的数据的UITableView委托方法didSelectRowAtIndexPath方法。如果字典有子类别我打印日志说“单元格不可点击”。对于正常的字典打印日志说“单元格是可点击的”。

检查下面的代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *dictSubCat=[[arr objectAtIndex:indexPath.row] objectForKey:@"child"]; 

    if ([dictSubCat isKindOfClass:[NSNull class]] || dictSubCat==nil) 
    { 
     NSLog(@"cell is clickable"); 
    } 
    else 
    { 
     NSLog(@"cell is not clickable"); 
    } 


} 
0

试试这个....

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) 
{ 
    [tableView beginUpdates]; 
    // set initial height for row 
    self.expandedIndexPath = nil; 
    [tableView endUpdates]; 

} 
else 
{ 
self.expandedIndexPath = [NSIndexPath indexPathForRow:indexPath.row  inSection:indexPath.section]; 

    [tableView beginUpdates]; 

    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) 
    { 
     self.expandedIndexPath = indexPath; 

    if ([[[[data objectForKey:@"parent_category_list"] objectAtIndex:indexPath.row] objectForKey:@"child"] count]==0) 
     { 
      // set here expanded height for row 
     // clickable.... 
     } 

     else{ 
      // no clickable... 
     } 


    } 

    else 
    { 
    self.expandedIndexPath = nil; 
    } 

[tableView endUpdates]; 
} 
} 
相关问题