gpt4 book ai didi

ios - Swift:如何在动态 UITableView 中使用静态单元格

转载 作者:搜寻专家 更新时间:2023-11-01 06:44:39 26 4
gpt4 key购买 nike

static
dynamic
dynamic
dynamic
..
..
dynamic

我有一个包含动态内容的动态表列表。在列表的顶部,我需要一个静态单元格。

并尝试在我的静态单元格中添加一个标签来尝试功能。

我的静态单元格的标识符是:firstCell

动态单元格的标识符是:单元格

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 5
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

// Configure the cell...

cell.textLabel?.text = "test"


return cell
}

此代码在我的动态单元格中返回 5 次“测试”。当我尝试添加标签并使用静态单元格创建导出时,出现错误。

我在 stackoverflow 上进行了 google 和搜索,但没有快速版本的解决方案。怎么做到的?

编辑以改进问题:

实际上我需要两个部分,第 1 部分将是静态内容(我将以编程方式创建它。例如,将使用 uidatepicker、uipicker 等等......),第 2 部分将只使用一个动态数组(这部分没问题)

最佳答案

你试过这样的事情吗?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

if (indexPath.row == 1) {
cell.textLabel?.text = "test"
} else {
// Configure the cell...
}

return cell
}

关于ios - Swift:如何在动态 UITableView 中使用静态单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31718047/

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