gpt4 book ai didi

ios - 快速创建表

转载 作者:行者123 更新时间:2023-11-30 13:34:35 25 4
gpt4 key购买 nike

我通常使用 MVC、HTML 和 JavaScript。因此我习惯使用 HTML 表格。我在 xcode 中制作了一个用 Swift 编写的 iOS 应用程序,它通过自定义单元格显示表格(以下代码):

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

//Load cell

let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! StatModelViewCell
//Map data
let data = TableData.ListOfStatsModels[indexPath.row]

if(Landscape == true)
{
//Map data to elements
cell.LabelMemberName.text = data.MemberName
cell.LabelGP.text = "GP:" + String(data.GP)
cell.LabelW.text = "W:" + String(data.W)
cell.LabelD.text = "D:" + String(data.D)
cell.LabelL.text = "L:" + String(data.L)


cell.LabelGoalsScorePositive.hidden = false
cell.LabelGoalsScorePositive.text = "+" + String(data.GoalsScorePositive)
cell.LabelGoalsScoreNegative.hidden = false
cell.LabelGoalsScoreNegative.text = "-" + String(data.GoalsScoreNegative)
cell.LabelP.hidden = false
cell.LabelP.text = "P:" + String(data.P)
cell.LabelP_GP.hidden = false
cell.LabelP_GP.text = "P/GP:" + String(data.P_GP)
}
else
{
//Map data to elements
cell.LabelMemberName.text = data.MemberName
cell.LabelGP.text = "GP:" + String(data.GP)
cell.LabelW.text = "W:" + String(data.W)
cell.LabelD.text = "D:" + String(data.D)
cell.LabelL.text = "L:" + String(data.L) + " P/GP:" + String(data.P_GP)

cell.LabelGoalsScorePositive.hidden = true
cell.LabelGoalsScoreNegative.hidden = true
cell.LabelP.hidden = true
cell.LabelP_GP.hidden = true
}

return cell

}

在 View 中看起来像这样: Horizontal iOS app

我真的很想让应用程序像普通的 HTML 表格一样,所以它看起来像这样: Horizontal website

但我真的不知道如何在 iOS 应用程序中制作表格。

我已经看过有关堆栈溢出的主题的其他帖子,但它们通常是用 Objective C 编写的,或者您必须为其使用自定义框架,并且它们通常响应速度不是很好。

任何人都可以帮我用 swift 编写一个简单的表示例,其中包含从数组读取的 header 和数据吗?

最佳答案

如果您想显示如图所示的布局,您可以尝试使用 Collection View 而不是 tableview,您可以尝试这个 github 演示 https://github.com/brightec/CustomCollectionViewLayout
我在我的项目中使用了这个,效果很好,看起来就像你需要的

它使用UICollectionViewLayout来创建布局并基于数组显示

如果您需要如图所示的边框,您可以为 ContentCollectionViewCell 图层提供边框,如下所示 contentCell.layer.borderWidth 以及 border 的其他属性

关于ios - 快速创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36222416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com