- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
tv.rowHeight = UITableViewAutomaticDimension;
tv.estimatedRowHeight = 44.0;
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
NSDictionary *Data5 = [pro1 objectAtIndex:indexPath.row];
NSString *name = [Data5 objectForKey:@"handle"];
UIButton *c3 = (UIButton *)[cell viewWithTag:775];
NSLayoutConstraint *height = [NSLayoutConstraint
constraintWithItem:c3
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:0
multiplier:0
constant:70];
NSLayoutConstraint *height2 = [NSLayoutConstraint
constraintWithItem:c3
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:0
multiplier:0
constant:0];
[c3 removeConstraint:height];
[c3 removeConstraint:height2];
[c3 addConstraint:height];
if ([name isEqualToString:@"abcd"]) {
UITableViewCell *updateCell2 = (id)[tableView cellForRowAtIndexPath:indexPath];
if (updateCell2){
[c3 removeConstraint:height];
[c3 removeConstraint:height2];
[c3 addConstraint:height2];
}
}else{
[c3 removeConstraint:height];
[c3 removeConstraint:height2];
[c3 addConstraint:height];
}
return cell;
}
首次加载时,状态正常。根据if else条件,c3按钮高度在第一次加载时是完美的。但是当我向上滚动然后所有的c3按钮被采取" height2"约束。如果其他条件搞砸了。你可以帮帮我吗?
结构是:
-tableView - 细胞 ---内容查看 - - 视图 -----按钮(C3)