我使用xib使用UITableViewCell。我想更改一些子视图的单元格内容视图的高度约束。代码是
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
simpleLearningCell*cell = [tableView dequeueReusableCellWithIdentifier:@"simpleCell"];
if (cell == nil) {
cell = [[simpleLearningCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"simpleCell"];
}
cell.lblName.text = [NSString stringWithFormat:@"%@",@"Vipin Sharma @ WDP Technologies Pvt Ltd"];
cell.lblTxtDetail.text = @"There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200.";
[cell.btnShare setButtonWithTitle:@"share with collegue" iconName:@"sharearrow" andWidthConstraints:cell.btnshareWidthConstraint];
[cell.btnComment addTarget:self action:@selector(doComment:) forControlEvents:UIControlEventTouchUpInside];
cell.btnComment.tag = indexPath.row+1;
if (indexPath.row == selectIndex) {
if (cell.txtCommentViewHeight.constant == 0) {
cell.txtCommentViewHeight.constant = 43;
}else{
cell.txtCommentViewHeight.constant = 0;
}
}else{
cell.txtCommentViewHeight.constant = 0;
}
return cell;
}
单击按钮时的方法调用
#pragma mark: do comment
-(void)doComment:(UIButton*)sender{
selectIndex = (int)sender.tag-1;
NSIndexPath*indexPath = [NSIndexPath indexPathForRow:sender.tag-1 inSection:0];
[self.tblView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
当我重新加载UITableView
时,它会自动滚动到顶部。 2次点击后cell.txtCommentViewHeight
的常数也会发生变化。