gpt4 book ai didi

swift - 无法为特定设备自定义 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 13:54:23 24 4
gpt4 key购买 nike

enter image description here

我使用的是 devicekit,这意味着如果手机检测到它的类型(5s、6 等...),那么它将加载我概述的一组特定约束。所以我为 Xs 设计了我的表格 View 单元格的约束,但是在使用 DeviceKit 并将它们设置为 5s 时,它不会更新它们。这是代码。此函数加载在 View 中。 加载。

func deviceKitConstraints() {
if device.isOneOf(smallGroup) {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomTableViewCell
cell.regoAnswer.center = CGPoint(x: self.view.center.x, y: self.view.center.y)
return cell
}
}

任何帮助将不胜感激

如果此设备的更新/约束有效,它就不会离开屏幕。

最佳答案

你的方法在另一个方法中,如果这应该是一个委托(delegate)方法,这会使它不可见。

将它放在 View Controller 的全局范围内,并根据方法内部的条件设置它的单元格(如果它是 UITableViewController,请在此方法之前放置 override 关键字)

class ViewController: UIViewController {

...

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if device.isOneOf(smallGroup) {
... // small
} else {
... // large
}
}

}

关于swift - 无法为特定设备自定义 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54076040/

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