本文介绍了从 SwiftUI 列表访问底层 UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 List 视图,有没有办法访问(并因此修改)底层 UITableView 对象,而无需将整个 List 重新实现为UIViewRepresentable?

Using a List view, is there a way to access (and therefore modify) the underlying UITableView object without reimplementing the entire List as a UIViewRepresentable?

我已经尝试在我自己的 UIViewRepresentable 中初始化一个 List,但是我似乎无法在需要时让 SwiftUI 来初始化视图,而且我只需获取一个没有子视图的空基本 UIView.

I've tried initializing a List within my own UIViewRepresentable, but I can't seem to get SwiftUI to initialize the view when I need it to, and I just get an empty basic UIView with no subviews.

这个问题是为了帮助找到SwiftUI 中的底部优先滚动的答案.

This question is to help find an answer for Bottom-first scrolling in SwiftUI.

或者,在 SwiftUI 中重新实现 UITableView 的库或其他项目也可以回答这个问题.

Alternatively, a library or other project that reimplements UITableView in SwiftUI would also answer this question.

推荐答案

答案是否定的. 从 iOS 13 开始,SwiftUI 的 List 目前并非旨在取代 UITableView 的所有功能和可定制性.它旨在满足 UITableView 最基本的使用:一个标准外观、可滚动、可编辑的列表,您可以在其中在每个单元格中放置一个相对简单的视图.

The answer is no. As of iOS 13, SwiftUI's List is not currently designed to replace all the functionality and customizability of UITableView. It is designed to meet the most basic use of a UITableView: a standard looking, scrollable, editable list where you can place a relatively simply view in each cell.

换句话说,您放弃了可定制性,因为可以自动为您实现滑动、导航、移动、删除等操作.

In other words, you are giving up customizability for the simplicity of having swipes, navigation, moves, deletes, etc. automatically implemented for you.

我确信随着 SwiftUI 的发展,List(或等效的视图)将变得更加可定制,我们将能够执行诸如从底部滚动、更改填充等操作.最好的方法是确保发生这种情况是为了向 Apple 提交反馈建议.我相信 SwiftUI 工程师已经在努力设计将在 WWDC 2020 上出现的功能.他们在指导社区想要和需要的方面的投入越多越好.

I'm sure that as SwiftUI evolves, List (or an equivalent view) will get more customizable, and we'll be able to do things like scroll from the bottom, change padding, etc. The best way to make sure this happens is to file feedback suggestions with Apple. I'm sure the SwiftUI engineers are already hard at work designing the features that will appear at WWDC 2020. The more input they have to guide what the community wants and needs, the better.

这篇关于从 SwiftUI 列表访问底层 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:12