我有字典结构,如下
{
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";
}
);
}
我想在UITableView
中安排上述词典,如果词典有子类别即。子字典然后单元格应该是可扩展的,或者如果没有子类别那么那应该是正常的单元格。哪个应该是可点击的。
我该如何设置?
答案 0 :(得分: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");
}
}
答案 1 :(得分: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];
}
}