简体   繁体   English

我们可以在UITableViewCell中添加滚动视图吗?

[英]Can we add a scroll view inside UITableViewCell?

I have requirement where I have to show some images which are differentiated according to Groups they belong to. 我有要求我必须显示一些根据他们所属的组区分的图像。 I have used a table view to view images listed under groups. 我使用表格视图来查看组下列出的图像。 User has to scroll horizontally to view more images in a particular group. 用户必须水平滚动才能查看特定组中的更多图像。 Can we add a scroll view to tableview row to allow user to scroll list of images horizontally? 我们可以向tableview行添加滚动视图以允许用户水平滚动图像列表吗? I searched a bit, some comments say its not allowed in apple's HIG some comments say You can add a UIScrollView to a UITableViewCell and as long as you set the contentSize property of the UIScrollView correctly then the UIScrollView will scroll correctly in the horizontal axis 我搜索了一下,有些评论说它在Apple的HIG中不允许有些评论说你可以将UIScrollView添加到UITableViewCell,只要你正确设置UIScrollView的contentSize属性,那么UIScrollView将在水平轴上正确滚动

May I get any confirmation on this ?? 我可以得到任何确认吗? Or any alternative approach to achieve horizontal and vertical scrolling for different data without using tableview 或者在不使用tableview的情况下实现不同数据的水平和垂直滚动的任何替代方法

Of course you can add scrollView in tableView. 当然,您可以在tableView中添加scrollView。

 UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];            
 [cell.contentView addSubview:scrollView];

Now you can set properties for scroll view accordingly. 现在,您可以相应地设置滚动视图的属性。

Yes it is definitively possible and reasonable. 是的,这绝对是可能和合理的。

Here is an excellent tutorial by Felipe Laso that explains it step by step: 这是Felipe Laso优秀教程逐步解释:

How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 1 如何使用像Pulse Pulse App那样的水平表接口:第1部分

How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 2 如何使用像Pulse News App一样的水平表接口:第2部分

BTW, the approach described in that tutorial is way more efficient than adding a UIScrollview to each cell. 顺便说一下,该教程中描述的方法比向每个单元格添加UIScrollview更有效。

Sure, this is possible. 当然,这是可能的。 A UIScrollView inside a UITableCellView will work fine - the HIG says no, probably because it'll be hard to use. UITableCellView中的UIScrollView可以正常工作--HIG说不,可能是因为它很难使用。 The user would have to accuratley scroll either up/down, or left/right and it might be annoying. 用户必须向上/向下或向左/向右滚动,这可能会令人讨厌。 Shouldn't take long to knock together a quick test. 不应该花很长时间来快速测试。

I have an app with 2 scrollviews - one that allows horizontal scroll, and then inside that another scrollview which allows vertical scroll. 我有一个带有2个滚动视图的应用程序 - 一个允许水平滚动,然后在另一个滚动视图内部允许垂直滚动。 The idea is that the user can flick up/down a page, then also flick left/right across pages. 想法是用户可以向上/向下翻页,然后在页面上向左/向右翻动。

It's not that nice to use, but it's what my client wanted ;) 这不是很好用,但这是我的客户想要的;)

To make a UIScrollView only respond to horizontal or vertical scroll is all about setting the correct contentSize. 要使UIScrollView仅响应水平或垂直滚动​​,所有关于设置正确的contentSize。 Hope this is some help. 希望这是一些帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM