UITableView within UIScrollView using autolayout

前端 未结 5 1130
渐次进展
渐次进展 2020-11-28 18:07

At the moment, I\'m using a UITableView along with other views that are contained in a UIScrollView. I want the UITableView to have it

5条回答
  •  生来不讨喜
    2020-11-28 18:35

    Here is the obj-C version. It's based on a solution from user @MuHAOS

    @implementation SizedTableView
    
    - (void)setContentSize:(CGSize)contentSize {
      [super setContentSize:contentSize];
      [self invalidateIntrinsicContentSize];
    }
    
    - (CGSize)intrinsicContentSize {
      [self layoutIfNeeded]; // force my contentSize to be updated immediately
      return CGSizeMake(UIViewNoIntrinsicMetric, self.contentSize.height);
    }
    
    
    @end
    

提交回复
热议问题