問題描述
我有 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 并接收單元格點擊?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!