一直想动态的显示或者隐藏某一行,终于摸索出来了!
step1:
先在这个方法-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath里,指定你想隐藏的那行:
if (indexPath.row == 0) {
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 12, 75, 20)];
dateLabel.text = @"汇报时间:";
[cell.contentView addSubview:dateLabel];
mDateTime = [[UITextField alloc] initWithFrame:CGRectMake(92, 7, 210, 30)];
mDateTime.text = @"时间";
[cell.contentView addSubview:mDateTime];
cell.hidden = YES;(重点是这行)
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0) {
return 0;(将高度设为0)
}