我正在使用一个自定义 UITableViewCell ,顶部有一个UILabel ,一个UIButton就在标签下面,另一个 UILabel就在这个按钮下面。
最终的 UILabel 最初是隐藏的,当调用按钮动作时会打开。所有标签和单元格的高度都是动态的。
但
当我选择按钮时,单元格将其内容视图转移到。中央
我需要单元格的内容从原点本身开始。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ReferenceCell";
ReferenceiPadTableCell *cell = (ReferenceiPadTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ReferenceiPadTableCell" owner:self options:Nil];
cell = [nib objectAtIndex:0];
cell.accessoryView = nil;
}
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
NSDictionary *referenceDictionary = [self.referencesList objectAtIndex:indexPath.row];
NSString *nameString = [referenceDictionary objectForKey:@"name"];
CGSize labelSize = [nameString sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:CGSizeMake(listTableView.frame.size.width - 15, 125)
lineBreakMode:UILineBreakModeWordWrap];
labelSize.height = labelSize.height > 96? labelSize.height : 96;
cell.l1.text = nameString;
cell.l1.frame = CGRectMake(cell.l1.frame.origin.x, 6, cell.l1.frame.size.width, labelSize.height);
cell.button.tag = [[referenceDictionary objectForKey:@"sort"] intValue];
[cell.button addTarget:self action:@selector(showList:) forControlEvents:UIControlEventTouchUpInside];
cell.l2.hidden = YES;
cell.button.frame = CGRectMake(cell.button.frame.origin.x, cell.l1.frame.origin.y+ labelSize.height + 1, cell.l1.frame.size.width, cell.l1.frame.size.height);
if ([self.showList objectForKey:[NSString stringWithFormat:@"showList-%d", indexPath.row]] )
{
cell.l2.hidden = NO;
NSDictionary *dic = [self.abstractList objectAtIndex:indexPath.row];
NSString *abtString = [dic objectForKey:@"name"];
CGSize absSize = [abtString sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:CGSizeMake(tableView.frame.size.width - 15, 125)
lineBreakMode:UILineBreakModeWordWrap];
cell.l2.frame = CGRectMake(cell.button.frame.origin.x, cell.button.frame.origin.y+ cell.button.frame.size.height + 3, cell.button.frame.size.width, absSize.height);
cell.l2.text = abtString;
}
return cell;
}