How to use UITableView inside UIScrollView and receive a cell click?(如何在 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 添加到此 UIScrollView. 容器.这有效,表格视图显示正确,但无法接收单元格点击.PlaceDetailsViewController 的 viewDidLoad 中的 content
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 原样,所以没有逻辑原因不能直接使用.有什么建议?
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
苹果说:
重要提示:您不应将 UIWebView 或 UITableView 对象嵌入UIScrollView 对象.如果这样做,可能会导致意外行为因为两个对象的触摸事件可能会混淆和错误处理.
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 并接收单元格点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 UIScrollView 中使用 UITableView 并接收单元格
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
