【发布时间】:2017-03-23 06:39:34
【问题描述】:
如何根据单元格中的标签文本(动态)增加单元格高度。在下面的代码中 lblAnswer 正在获取动态数据,基于此单元格高度应该增加。尝试了下面的代码,但对我不起作用。 TIA
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
EmpViewCell *cell = (EmpViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[EmpViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.lblAnswer.lineBreakMode = NSLineBreakByWordWrapping;
cell.lblAnswer.numberOfLines = 0;
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"EmpViewCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (EmpViewCell *) currentObject;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
}
}
NSMutableDictionary* emmpdict = [_emparr objectAtIndex:indexPath.row];
cell.lblEmpName.text = [NSString stringWithFormat:@"%@",[emmpdict objectForKey:@"EmployeeName"]];
cell.lblQuestion.text=[NSString stringWithFormat:@"%@",[emmpdict objectForKey:@"Question"]];
cell.lblAnswer.text=[NSString stringWithFormat:@"%@",[emmpdict objectForKey:@"Answer"]];
return cell;
}
【问题讨论】:
-
stackoverflow.com/a/39888662/6656894这个答案非常适合您的问题
标签: ios objective-c iphone xcode custom-cell