更改过静态表单元的大小和位置之后滚动表视图,原先更改的表单元的大小和位置又变回去了,怎么办?

解决方案 »

  1.   

    比如说我storyboard里的UITableViewController里有一个静态的表单元,关联的outlet定义为cell,然后通过代码更改此静态表单元的大小:CGRect  frame = self.cell.frame;
          frame.size.height = frame.size.height + 50;
          self.cell.frame = frame;
    当时此静态表单元的大小加了50,然后我向下滚动滚动条使此静态表单元离开屏幕的显示范围之后再让其显示在屏幕上,刚刚加的50的高度就没了,这个静态表单元还是恢复了原来的高度。
      

  2.   

    是不是在调用
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath 
    中设置了一个固定的值了。这样在滚动显示的时候会调用这个代理方法返回cell的高度。
    解决的办法是
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath {
           UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];       return cell.frame.size.height;
    }
      

  3.   

    建一个bool 数组。去记录是否增加了50. 在-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath方法里,根据bool值,去判断,取高度。
      

  4.   

    cell最好不要使用outlet,可以使用tag来获取某一行,然后指定它的高度,或者
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath {
           return cell.frame.size.height;
    }