简体   繁体   English

如何为不同的 iOS 版本显示不同的静态单元格?(静态`UITableView`)

[英]How to show different static cells for different iOS versions?(Static `UITableView`)

I'm creating a Setting Screen with the help of static UITableVIew .我在静态UITableVIew的帮助下创建了一个设置屏幕。

Now, there are certain cells(Functions) that doesn't work in some iOS version ,so I want to hide them from my tableView in a way that doesn't affect other cell.现在,某些单元格(函数)在某些iOS 版本中不起作用,因此我想以不影响其他单元格的方式将它们从我的 tableView 中隐藏。

EG - in the below Image , Change App Icon function won't work in iOS version less than 10.3 so I want to hide it for devices only which have lower iOS version than 10.3 (It should be displayed for iOS 10.3+) EG - 在下面的图像中, Change App Icon功能在低于 10.3 的 iOS 版本中不起作用,所以我只想为 iOS 版本低于 10.3 的设备隐藏它(它应该在 iOS 10.3+ 中显示)

Thanks in Advance提前致谢

You should use the heightForRowAtIndexPath method and inside it, check the iOS version and return the height of cells based on it.您应该使用 heightForRowAtIndexPath 方法并在其中检查 iOS 版本并基于它返回单元格的高度。

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    if #available(iOS 13.0, *) {
        return 40
    } else {
        return ( (indexPath.row == 3) ? 0 : 50)
    }
}

As its a static table view, you already know the row and section.作为静态表视图,您已经知道行和节。 So in the above code, we are hiding the third row if the iOS version is below 13.0 by making its height 0. For other rows, it will make height as 50所以在上面的代码中,如果iOS版本低于13.0,我们通过将其高度设为0来隐藏第三行。对于其他行,它将高度设为50

you can use the available attribute for the same while in cellForRowAtIndexPath function.您可以在 cellForRowAtIndexPath 函数中使用可用属性。 In your cellForRowAtIndexPath try the following:在您的cellForRowAtIndexPath尝试以下操作:

if #available(iOS 10.3, *) {
    //load all cells here
  } else {
    // load just the ones you want excluding those which won't work with iOS version less than 10.3
 }

Your question isn't clear enough.你的问题不够清楚。 How do you implement your cells?你如何实现你的细胞? If you use a storyboard – you should hide particular cells.如果您使用故事板 - 您应该隐藏特定的单元格。 If you use the code, you should check the iOS version at each time of table handling: from cell registering until each delegate method in order to provide the corresponding information.如果你使用代码,你应该在每次表处理时检查iOS版本:从单元格注册到每个委托方法,以便提供相应的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM