IOS: choice a UIScrollView or a UITableView

2019-03-24 19:25发布

In my app I should create a view with a loto of informations; these informations are divided in 4 section, every section can contain text, images lists ecc...

this is a brutal example...

enter image description here

Now I'm dubious to what type of solution to adopt.

In a my fast opinion a big scrollview is difficult to organize. And a big tableview with section is complicated to organize with code... What are your ideas?

3条回答
爷的心禁止访问
2楼-- · 2019-03-24 19:43

You should go with UITABLEVIEW, easy to manage easy to understand, more reusability and good memory management

If you have lots of content to scroll through, a UITableView might help you with keeping memory usage down.

When a cell scrolls out of sight, it gets removed from the view and kept around by the UITableView for later use (via -dequeueReusableCellWithIdentifier:). If you run low on memory then I believe that those invisible views (UITableViewCells) will get released. This basically means that your app will only keep views in memory that are actually visible. More will be cached, but can be purged any time if needed.

If you display a lot of data, and just add it all to a UIScrollView it will potentially use much more memory than if you used a UITableView. You might have to implement a similar mechanism to what UITableView does to remove (and potentially release) invisible views.

So, you can basically achieve the same effect, but a UITableView does a lot of that work for you already.

If you display lots of data (probably more than about two screens full) I'd lean towards using a UITableView.

查看更多
Bombasti
3楼-- · 2019-03-24 20:02

UITableView is optimized for "reusable" cells, which is appropriate for scrolling in long lists. Another benefit of using an UITableView, as others suggested, is that it only instantiate visible cells, so memory consumption is reduced.

In your case, since your content looks specific and non repetitive, I would suggest using a simple UIScrollView which is easier to use. (UITableView inherits from UIScrollView btw)

If memory/performance is an issue, then prefer UITableView or simply write your own logic to only instantiate views that are visible (by using scrollOffset for example)

EDIT:

On second thoughts, in your case, UICollectionView is surely a better candidate than UITableView. Especially if you plan some day to do something like a 2 columns layout on iPad...

查看更多
该账号已被封号
4楼-- · 2019-03-24 20:04

This sort of thing is very easy to create in Interface Builder now with static cells; you can layout the entire interface visually and set up outlets for the cells (and/or their subviews) in order to configure the content in your view controller.

查看更多
登录 后发表回答