gpt4 book ai didi

ios - 将选定行的行高设置为 0 (swift)

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

在我的应用程序中,我在 UITableView 上显示了“组”物种。

有些群组是免费的,有些是应用内购买的。

作为应用内购买的组在 cellForRowAtIndexPath 中设置了该行上挂锁的 UIImage。

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: Resource.SpeciesCell)!

let specieImage: UIImageView = cell.viewWithTag(Resource.SpeciesImageTag) as! UIImageView
let specieName: UILabel = cell.viewWithTag(Resource.SpeciesNameTag) as! UILabel
let specieGenus: UILabel = cell.viewWithTag(Resource.SpeciesGenusTag) as! UILabel
let specieFamily: UILabel = cell.viewWithTag(Resource.SpeciesFamilyTag) as! UILabel

specieName.text = self.species[(indexPath as NSIndexPath).row].specie
specieFamily.text = ""
specieGenus.text = AppDelegate.getRLDatabase().getSubGroupName_BySpecieName(specieName.text!)


let padLock: UIImageView = cell.viewWithTag(Resource.SpeciesCategoryLabelTag) as! UIImageView

padLock.image = UIImage(named: "PadlockIcon")
padLock.alpha = 0.7

let fishesPurchased = UserDefaults.standard.bool (forKey: "ReefLife5Fishes")
let sharksPurchased = UserDefaults.standard.bool (forKey: "ReefLife6Sharks")
let turtlesPurchased = UserDefaults.standard.bool (forKey: "ReefLife8Turtles")
let seahorsesPurchased = UserDefaults.standard.bool (forKey: "ReefLife9Seahorses")
let vertebratesPurchased = UserDefaults.standard.bool (forKey: "ReefLife3Vertebrates")
let fullPurchased = UserDefaults.standard.bool (forKey: "ReefLife1Full")

padLock.isHidden = false
specieImage.alpha = 1.0

let speciesGroup = self.species[(indexPath as NSIndexPath).row].group

if fullPurchased == true {

padLock.isHidden = true
specieImage.alpha = 1.0

} else if speciesGroupVertebratesArray.contains(speciesGroup) {

if vertebratesPurchased == true {

padLock.isHidden = true
specieImage.alpha = 1.0

} else {

if speciesGroup == "Fish" {
if fishesPurchased == true{
padLock.isHidden = true
specieImage.alpha = 1.0

} else{
specieImage.alpha = 0.5
}
} else if (speciesGroup == "Sharks" || speciesGroup == "Rays" ) {
if sharksPurchased == true{
padLock.isHidden = true
specieImage.alpha = 1.0

} else{
specieImage.alpha = 0.5
}
} else if speciesGroup == "Syngnathiformes" {
if seahorsesPurchased == true{
padLock.isHidden = true
specieImage.alpha = 1.0

} else{
specieImage.alpha = 0.5
}
} else if speciesGroup == "Reptilia" {
if turtlesPurchased == true{
padLock.isHidden = true
specieImage.alpha = 1.0

} else{
specieImage.alpha = 0.5
}
}
}

}
....

我有一个基于 UISwitch 的选项设置来“隐藏锁定的项目”

当用户选择这个时,我想隐藏锁定的组(或未购买的元素)。我认为实现此目的的最佳方法是通过将行高设置为 0 来隐藏特定行。

我正在努力使用 indexPath.row 将行高设置为 0,因为 indexPath.row 不接受 CGFloat 命令。

建议?

编辑:意识到我需要使用 heightForRowAt indexPath: IndexPath 函数,但我很难将它分配给 indexPath.row。

也许更好的问题是:如何设置它以便我知道哪个 indexPath.row 具有“padLock.isHidden == false”。

最佳答案

行高是在单独的委托(delegate)函数中设置的,而不是 cellForRowAt 设置函数。尝试这样的事情:

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
rowHeight = [your default row height]

record = frc.object(at: indexPath) as [YourEntity]

if record.[what indicates locked] == true
{
rowHeight = 0
}

return CGFloat(rowHeight)
}

关于ios - 将选定行的行高设置为 0 (swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41366231/

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