点击时更改TableView高度(在xib中使用autolayout)

时间:2016-03-02 11:38:47

标签: ios objective-c xcode uitableview xib

我的ViewController在最初加载时看起来像这样:

initially

点按“显示”按钮时,必须改变如下: When ShowButton tapped

我的代码是:

- (IBAction)show:(id)sender {
 [self change];
 [tableView reloadData];
}
- (IBAction)close:(id)sender { 
 [self change];
 [tableView reloadData];
}

-(void)change{
  //assigning initial bounds to frame-1
  CGRect frame1=CGRectMake(0, _pastProcessTV.frame.origin.y, self.view.bounds.size.width, self.pastProcessTV.bounds.size.height); 
  //assigning new bounds to frame-2
  CGRect frame2=CGRectMake(0, **CGFloat y**,self.view.bounds.size.width,***CGFloat height***);

   if (_showFullButton.isTouchInside) {
          tableView.frame = frame2;
    }
   else{
          tableview.frame = frame1;
   }
}

我尝试了不同的方法。它不起作用。任何人都可以帮我提供Y坐标和宽度

2 个答案:

答案 0 :(得分:1)

当您使用自动布局时,您必须选择tableview的topconstraint出口,当您想要展开它时,将其值设置为0

所以它会按预期工作

如果您使用的是iOS 7

[self.view layoutIfNeeded]是强制性的

答案 1 :(得分:-1)

请关闭故事板中的自动布局

image