如何在UIScrollView中使用UITableView并接收单元格? [英] How to use UITableView inside UIScrollView and receive a cell click?

查看:111
本文介绍了如何在UIScrollView中使用UITableView并接收单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 DiscountListTableViewController 在我的应用中显示为单独的屏幕。但是还有另一个屏幕( PlaceDetailsViewController ),我需要在底部显示相关的折扣。

I have DiscountListTableViewController that is shown as a separate screen in my app. But there's another screen (PlaceDetailsViewController) where I need to show related discounts at the bottom.

目前, PlaceDetailsViewController.view UIScrollView 作为容器,我将 DiscountListTableViewController.tableView 添加到 viewDidLoad中的 UIScrollView.content 容器 PlaceDetailsViewController 。这有效,表格视图显示正确,但无法接收单元格点击。

Currently, PlaceDetailsViewController.view has UIScrollView as a container and I'm adding DiscountListTableViewController.tableView to the this UIScrollView.content container in viewDidLoad of PlaceDetailsViewController. This works and the table view is shown correctly, however unable to receive cell clicks.

我知道 UITableView 继承自 UIScrollView 并且不知何故(但不限制)。但是,从松散耦合的角度来看,每个组件的设计应该可以在别处独立使用,在我的例子中它是 DiscountListTableViewController

I know UITableView inherits from UIScrollView and it's somehow not advised (but not restricted). However, from loose coupling point of view, every component should be designed in a way it could be independently used elsewhere, and it's DiscountListTableViewController in my case.

PlaceDetailsViewController 组件只需要 DiscountListTableViewController as-is,所以没有逻辑上的理由不能直接使用它。有什么建议么?

PlaceDetailsViewController component just needs DiscountListTableViewController as-is, so there's no logic reason why it can't be used directly. Any suggestions?

推荐答案

答案:不要这样做。

UITableview 继承自----> UIScrollView:UIView:UIResponder:NSObject

UITableview is inherited from ----> UIScrollView : UIView : UIResponder : NSObject

Apple说:


重要:您不应该在
UIScrollView对象中嵌入UIWebView或UITableView对象。如果这样做,意外行为可能导致
,因为两个对象的触摸事件可能混淆并且错误地处理

Important: 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.

这篇关于如何在UIScrollView中使用UITableView并接收单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆