gpt4 book ai didi

ios - 隐藏某个表格行 - Swift 4

转载 作者:行者123 更新时间:2023-11-28 10:37:01 25 4
gpt4 key购买 nike

我有

包含 5 个位置的表。

var places =  ["lat": "42.61964890000001", "country": "United States", "name": "39 Cosgrove St", "lon": "-71.3031683"]
[["lat": "42.6285025", "country": "United States", "name": "138 B St", "lon": "-71.3288776"], ["lat": "42.6334255", "country": "United States", "name": "137 Pine St", "lon": "-71.3321021"], ["lat": "42.6225646", "country": "United States", "name": "98 Marriner St", "lon": "-71.31320219999999"], ["lat": "42.6252232", "country": "United States", "name": "48 Houghton St", "lon": "-71.3243308"], ["lat": "42.61964890000001", "country": "United States", "name": "39 Cosgrove St", "lon": "-71.3031683"]]

enter image description here

我要

防止在我的表格中显示列表中的事件位置。

我试试

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

if places[indexPath.row]["name"] != nil && places[indexPath.row]["name"] != places[activePlace]["name"] {
cell.textLabel?.text = places[indexPath.row]["name"]
}

return cell
}

我得到了

要隐藏的文本,但它似乎留下了一个看起来很糟糕的空白区域。

enter image description here

我希望

有人可以阐明这一点。

最佳答案

这个

if places[indexPath.row]["name"] != nil && places[indexPath.row]["name"] != places[activePlace]["name"] {
cell.textLabel?.text = places[indexPath.row]["name"]
}

导致返回一个空单元格(如果不是出列的单元格),您需要从数据源数组中删除该信息(如果有许多事件单元格,则可以将其保留在另一个 var 或数组中)并重新加载表,你可以使用这个

places = places.compactMap{ $0["name"] }

从开头删除 nils


像这样声明 2 个临时变量

var tem:[String:String]? // pls create a model don't use array of dics
var activeIndex:Int?

假设你在一个方法中改变 active,它给新的事件索引说它是 neActiveIndex 那么你会做

if let oldValue = tem && oldActi = activeIndex { // is it the first process 
places.insert(oldValue,at:oldActi) // return it to it's place
}

// remove the new index

tem = places.remove(at: neActiveIndex) // remove also returns the deleted object
activeIndex = neActiveIndex

然后重新加载表格

如果事件索引没有改变,它只是显示 1 次,那么不要保留任何内容,只需删除 viewDidLoad 中的事件索引,表格本身将在 vc 上重新加载启蒙

关于ios - 隐藏某个表格行 - Swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53091033/

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