1
在我的應用程序中,我在UITableView上顯示了物種的「組」。將行高設置爲0,對於選定的行(swift)
有些羣組是免費的,有些羣組是在應用內購買的。
應用內購買的羣組在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可以隱藏特定的行。
我很努力地將行高設置爲0,使用indexPath.row作爲它的indexPath.row不接受CGFloat命令。
對此提出建議?編輯: 實現我需要使用heightForRowAt indexPath:IndexPath函數,但我有一個困難的時間分配給indexPath.row。
也許更好的問題是:我如何設置它,以便我知道哪個indexPath.row具有「padLock.isHidden == false」。
謝謝,我一直在嘗試在heightForRow裏面,但是你的想法比我一直在嘗試的要多得多。上述唯一的問題是我無法弄清楚frc代表什麼? –
那就是我所謂的fetchedResultsController:private var frc = NSFetchedResultsController() –