gpt4 book ai didi

ios - 如何过滤 TableView 单元格以便过滤掉的单元格不会出现?

转载 作者:行者123 更新时间:2023-11-30 13:49:42 24 4
gpt4 key购买 nike

我正在尝试根据用户在 UIPickerView 中所做的选择来更改显示的单元格。现在,我正在使用方法cell.hidden = true。然而,这样做的问题是单元格隐藏了,但存在隐藏单元格大小的空白区域。我想这样做,以便从 TableView 中隐藏/删除单元格(保存数据)。这是当前代码。

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var numRows = tableData.count
if(timeTextfield.text == timeData[1]) {
numRows = 25
}
else if(timeTextfield.text == timeData[2]) {
numRows = 30
}
return numRows
}

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

let cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TblCell
var lblOneBool = true
var lblTwoBool = true
var lblThreeBool = true
var lblFourBool = true

if(timeTextfield.text == timeData[2]) {
cell.hidden = false
cell.lblTime.text = tableData[indexPath.row + 25]
cell.lblOne.text = lblOneData[indexPath.row + 25]
cell.lblTwo.text = lblTwoData[indexPath.row + 25]
cell.lblThree.text = lblThreeData[indexPath.row + 25]
cell.lblFour.text = lblFourData[indexPath.row + 25]
}
else {
cell.lblTime.text = tableData[indexPath.row]
cell.lblOne.text = lblOneData[indexPath.row]
cell.lblTwo.text = lblTwoData[indexPath.row]
cell.lblThree.text = lblThreeData[indexPath.row]
cell.lblFour.text = lblFourData[indexPath.row]
}

if(cell.lblOne.text != "Available") {
lblOneBool = false
}
if(cell.lblTwo.text != "Available") {
lblTwoBool = false
}
if(cell.lblThree.text != "Available") {
lblThreeBool = false
}
if(cell.lblFour.text != "Available") {
lblFourBool = false
}

if(playerTextfield.text == playersData[1]) {
if(lblOneBool || lblTwoBool || lblThreeBool || lblFourBool) {
cell.hidden = false
}
else {
cell.hidden = true
}
}
else if(playerTextfield.text == playersData[2]) {
if((lblOneBool && lblTwoBool) || (lblOneBool && lblThreeBool) || (lblOneBool && lblFourBool) || (lblTwoBool && lblThreeBool) || (lblTwoBool && lblFourBool) || (lblThreeBool && lblFourBool)) {
cell.hidden = false
}
else {
cell.hidden = true
}
}
else if(playerTextfield.text == playersData[3]) {
if((lblOneBool && lblTwoBool && lblThreeBool) || (lblOneBool && lblTwoBool && lblFourBool) || (lblOneBool && lblThreeBool && lblFourBool) || (lblTwoBool && lblThreeBool && lblFourBool)) {
cell.hidden = false
}
else {
cell.hidden = true
}
}
else if(playerTextfield.text == playersData[4]) {
if(lblOneBool && lblTwoBool && lblThreeBool && lblFourBool) {
cell.hidden = false
}
else {
cell.hidden = true
}
}
return cell
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 120
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let row = indexPath.row
performSegueWithIdentifier(conSegueIdentifier, sender: indexPath)
print(tableData[row])
if(timeTextfield.text == timeData[2]) {
tblIndex = row + 25
}
else {
tblIndex = row
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
//end of tableview

最佳答案

您可以采取多种不同的方法

一个简单的方法是实现 UITableView 委托(delegate)的 heightForRowAtIndexPath 并为不想显示的行返回 0

另一种方法是从 tableData 中完全删除这些行。所以也许有一个“filteredArray”和一个非过滤数组。这样,您可以在不过滤时始终返回到未过滤的数组

关于ios - 如何过滤 TableView 单元格以便过滤掉的单元格不会出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34440479/

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