如何在 UIScrollView 中使用 UITableView 并接收单元格点击?

How to use UITableView inside UIScrollView and receive a cell click?(如何在 UIScrollView 中使用 UITableView 并接收单元格点击?)
本文介绍了如何在 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.viewUIScrollView 作为容器,我将 DiscountListTableViewController.tableView 添加到此 UIScrollView.PlaceDetailsViewControllerviewDidLoad 中的 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 并接收单元格点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Resume game cocos2d(恢复游戏 cocos2d)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)