【问题标题】:Create a tableView inside UIView Swift在 UIView Swift 中创建一个 tableView
【发布时间】:2021-05-04 02:01:51
【问题描述】:

嗨 :) 我有一个 tableView,我想在我的 UITableViewCell 中有一个 tableView,现在我想在 UIView 类中创建一个自定义 tableView,然后使用 UIView 在 UITableViewCell 中呈现它,我想知道是有可能,或者我正在处理错误的问题:)

这是我想要实现的图片:Link

【问题讨论】:

    标签: ios swift uitableview uiview


    【解决方案1】:

    虽然您可以将UITableView 添加到任何UIView,这也意味着添加到UITableViewCell,但您尝试实现的目标看起来像UITableViewUITableView.Style.insetGrouped

    这种新的表格视图样式在 iOS13 中可用。

    只需使用这种样式初始化您的表格视图,例如:

    let tableView = UITableView(frame: .zero, style: .insetGrouped)
    

    您可以在此处查看文档:(https://developer.apple.com/documentation/uikit/uitableview/style/insetgrouped)

    在这个帖子里,有这个UITableView.Style的截图:

    TableView with inset grouped style: Have rounded corners even with hidden cells

    【讨论】:

    • @Iaka 哦,我明白了,问题是我的应用仅适用于 iOS 10 及更高版本的用户:\
    • 好吧,我发现我可以这样做:let tableView = UITableViewController(style: .grouped) 问题是,可以在 UIView 中做一个 uitableviewcontroller 吗?
    • 您可以将 UITableView(不是 UITableViewController)添加到 UIView。
    • 但是,我认为您应该能够继承UITableView 并将其外观修改为类似于.insetGrouped,而不是将UITableView 添加到UIView
    • 我在里面添加了一个tableView。一个 UIView,问题是我不能使用 .insetGrouped,因为它仅适用于 iOS13+ 并且该​​应用程序获得了 iOS10+ 的用户,哈哈,但感谢我解决它的帮助:)
    【解决方案2】:

    您可以使用inset grouped style 实现这种外观 在 UITableView 上并将sections 添加到 UITableView

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 1970-01-01
      相关资源
      最近更新 更多