I am able to make the content size of table to set as table height and modify the content size of scrollView by following way.
I just designed the table inside the scrollView and call to modify the height of table and content size of scrollView from viewDidAppear
My Code :
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.extraDesignAfterStoryboard();
}
override func viewDidAppear(animated: Bool) {
self.modifyContentHeight();
}
func extraDesignAfterStoryboard()
{
scrolVw = UIScrollView();
scrolVw.frame = CGRectMake(0, 64, self.view.frame.size.width, 200);
scrolVw.backgroundColor = UIColor.greenColor();
self.view.addSubview(scrolVw);
tblViewScr = UITableView(frame: CGRectMake(0, 80, scrolVw.frame.size.width, 120), style: UITableViewStyle.Plain);
tblViewScr.delegate = self;
tblViewScr.tag = 100;
tblViewScr.dataSource = self;
tblViewScr.scrollEnabled = false;
tblViewScr.backgroundColor = UIColor.redColor();
scrolVw.addSubview(tblViewScr);
}
func modifyContentHeight()
{
if(self.tblViewScr.contentSize.height > self.tblViewScr.frame.height){
var frame: CGRect = self.tblViewScr.frame;
frame.size.height = self.tblViewScr.contentSize.height;
self.tblViewScr.frame = frame;
var contentSize = self.scrolVw.contentSize;
contentSize.height = CGRectGetMaxY(self.tblViewScr.frame);
self.scrolVw.contentSize = contentSize;
}
}
It is working here in my Demo project. Can you check once, If it works for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.