【发布时间】:2016-04-18 01:40:26
【问题描述】:
我正在使用一个包含来自两个字典的对象的数组,并在具有不同标识符的第一个单元格上显示第一个字典的对象,并与第二个字典对象相同。
在 cellforrowatindexpath 中查看我的代码
static NSString *cellIdentifier = @"cellIdentifier1";
static NSString *customCellIdentifier = @"cellIdentifiercustom";
if (indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
ExcName = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 2.0, 250.0, 36.0)];
ExcName.font = [UIFont systemFontOfSize:12.0];
ExcName.textColor = [UIColor blackColor];
ExcName.textAlignment = NSTextAlignmentLeft;
ExcName.text=[[exerciseAr objectAtIndex:indexPath.row] objectForKey:@"activityname"];
ExcName.numberOfLines=3;
[cell.contentView addSubview:ExcName];
return cell;
}
else{
UITableViewCell *customcell = [tableView dequeueReusableCellWithIdentifier:customCellIdentifier];
// if (cell==nil)
{
customcell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:customCellIdentifier];
}
customcell.selectionStyle = UITableViewCellSelectionStyleNone;
ExcName = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 2.0, 250.0, 36.0)];
ExcName.font = [UIFont systemFontOfSize:12.0];
ExcName.textColor = [UIColor blackColor];
ExcName.textAlignment = NSTextAlignmentLeft;
ExcName.text=[[exerciseAr objectAtIndex:indexPath.row] objectForKey:@"exercisename"];
// ExcName.text=[[exerciseAr objectAtIndex:indexPath.row] objectForKey:@"exercisename"];
ExcName.numberOfLines=3;
[customcell.contentView addSubview:ExcName];
return customcell;
}
return nil;
}
现在我想如果任何字典为空,对应于该字典的单元格不应该是可见的,现在是可见的。
【问题讨论】:
-
如果在 heightforrowatindexpath 委托方法中特定字典为空,您可以将高度更改为 0
-
那么,你应该把这个逻辑放在
-tableView:numberOfRowsInSection:。 -
@Jaimish 不建议这样做(运行时会抱怨)。不要折叠单元格,而是告诉表格视图您需要显示的实际行数,并在每次调用 -tableView:cellForRowAtIndexPath:` 时返回一个完全配置的单元格。
-
@NicolasMiari 你能用编码解释一下吗
-
好的,然后@NavjotSingh 请告诉我你的 numberOfRowinSection 方法
标签: ios objective-c uitableview dictionary