gpt4 book ai didi

ios - 在uitableview中显示更多内容

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

默认情况下,每个部分最多应显示三个单元格。如果任何单元格包含三个以上的单元格,则应显示“显示更多”选项。如果点击“显示更多”,我想显示该特定部分中的其余单元格。我花了两天时间,没有任何结果。部分在表的顶部。根据所选的段,表格 View 加载单元格。每个段每个部分的代码都不同,因此 func cellForRowAtIndexPath: 变得非常大。我粗略地添加了代码。这段代码是我尝试过的。

if segmentName == .Feature || segmentName == .Services
{
if indexPath.section == 0
{
if boolShowFullFeature[indexPath.section] == false
{
if indexPath.row == showCells
{
return createShowMoreCell(indexPath.section)
}
else
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SearchListViewCell
var firstTitle = "", secondTitle = "", thirdTitle = "", recomendValue = "", starValue = ""

(firstTitle, secondTitle, thirdTitle, recomendValue, starValue) = model.foodValue[indexPath.row]
cell.configureCell(firstTitle, secondTitle: secondTitle, thirdTitle: thirdTitle, recomendValue: recomendValue, starValue: starValue)
return cell

最佳答案

我以前确实这样做过。这是示例代码:

var objects = [["1","2","3"],["q","w","e","r","t","y"],["z","x","c","v","b","n","m"]]
var sec = ["sec a","sec b","sec c"]
var showallSec = 0

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sec.count
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let items = objects[section].count

if items > 3{
if section == showallSec-1{
return items
}
return 4
}
return items
}

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

let object = objects[indexPath.section][indexPath.row]
cell.textLabel!.text = object
if(indexPath.section != showallSec-1){
if(indexPath.row == 3){
cell.textLabel!.text = "show more"
}}
return cell
}

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sec[section]
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.row == 3){
showallSec = indexPath.section + 1
tableView.reloadData()
}
}

关于ios - 在uitableview中显示更多内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34266955/

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