Ios 将选定行的行高设置为0(swift)
在我的应用程序中,我在UITableView上显示了物种的“组” 有些群组是免费的,有些是应用内购买 属于应用内购买的组在Ios 将选定行的行高设置为0(swift),ios,uitableview,swift3,heightforrowatindexpath,Ios,Uitableview,Swift3,Heightforrowatindexpath,在我的应用程序中,我在UITableView上显示了物种的“组” 有些群组是免费的,有些是应用内购买 属于应用内购买的组在cellForRowAtIndexPath中设置了该行挂锁的UIImage override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell
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
也许更好的问题是:如何设置它,以便知道哪个indexath.row具有“padLock.ishiden==false”。行高是在单独的委托函数中设置的,而不是在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)
}
行高是在单独的委托函数中设置的,而不是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)
}
您可以使用tableView(height forRow})方法 然后(用于重新加载tableView的布局),
使用方法:tableView.BeginUpdate,然后是tableView.EndingUpdate您可以使用方法tableView(height forRow}。) 然后(用于重新加载tableView的布局),
使用以下方法:tableView.BeginUpdate,然后是tableView.EndingUpdate谢谢,我一直在尝试在heightForRow内,但你的想法比我尝试的要近得多。上面提到的唯一问题是我无法理解frc代表什么?这正是我所说的我的fetchedResultsController:private var frc=NSFetchedResultsController()谢谢,我一直在heightForRow内尝试,但你的想法比我所尝试的要近得多。上面提到的唯一问题是我无法理解frc代表什么?这正是我所说的我的fetchedResultsController:private var frc=NSFetchedResultsController()