UITableViewCell outside of UITableView

﹥>﹥吖頭↗ 提交于 2019-12-18 14:55:35

问题


I notice that InterfaceBuilder has UITableViewCell in its library of objects I can drag onto a view. I wonder if it ever makes sense to use one outside of a UITableView.


回答1:


UITableViewCells are meant to be used in UITableViews only. Feel free to stick them elsewhere, but you do so at your own risk.




回答2:


I have tried this and yes it does not appear to work. Which is, of course, fair, given the purpose and use of cells.

A reason for wanting to do this, in my case I have the cell used in a table view, selecting a cell then pushes on another view, part of which is an exact repeat of the contents of the cell, shown at the top.

So it would be very convenient to simply place the cell at the top on the new view, and have it populated, without needing any extra code.

What I have done is loaded the cell from its nib, set it up, and then added the contentView of the cell to my new pushed view. This achieves the desired effect.




回答3:


Best to substitute the UITableViewCell with a UIView if you want to use it outside of table view... you can try to fake the disclousure indicator by drawing it yourself, or using an icon

If you want to reuse the code, you can put the login in a custom UIView subclass, which is used both in the cell and also in the regular UI

I would discourage using UITableViewCell outside of UItableView as tempting it may be... the cell conforms to reuse handling and layout resolutions, so while it may look fine, it is a misuse which can trigger unforeseen problems



来源:https://stackoverflow.com/questions/2770663/uitableviewcell-outside-of-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!