Dynamically setting size of frame of a UITableView

2019-06-11 03:43发布

I am using swift and have a story board containing a UIViewController which includes a UIScrollView with UITableView. storyboard hierarchy

What am I trying to do is to load an excel file in a table so I need to scroll horizontally. I can set the content size of scroll view with:

scrollView.contentSize = CGSize(width: 3500, height: scrollView.contentSize.height)

I do also need to set the size of frame of UITableView. When I set it from storyboard with the field shown it works, but when I set it programmatically from viewDidLoad method it does not work. The width value is shown as changed to 3500 but when I checked in tableView cellForRowAtIndexPath method, I see the value set in story board.

Need to change this from code

2条回答
老娘就宠你
2楼-- · 2019-06-11 03:57

Apple Documentation discourages you from embedding UITableView inside UIScrollView.

You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

Anyway are your UITableView and UIScrollView scrolling horizontally?

查看更多
狗以群分
3楼-- · 2019-06-11 04:12

Here is a sample project I just created to see if I could create what you are asking for.

https://github.com/joalbright/Excel

查看更多
登录 后发表回答