Xcode 9 Swift 4由于内存问题而终止(返回一个单元格)

问题描述 投票:-1回答:2

现在我知道还有很多其他问题存在同样的问题,但是,没有一个问题在我的问题上崩溃了。

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! CustomTableViewCell

    cell.selectionStyle = UITableViewCellSelectionStyle.none
    cell.cellView.layer.cornerRadius = cell.cellView.frame.height / 2

    cell.animalLbl.text = elements[indexPath.row]
    cell.animalImage.image = UIImage(named: elements[indexPath.row])
    cell.animalImage.layer.cornerRadius = cell.animalImage.frame.height / 2

    return cell
}

返回细胞

那是造成我问题的那条线。我的数组只有10个项目,它在模拟器上工作正常。在我在桌面视图中添加所有图像之前,它在我的iPad上工作正常。

这是我的阵列问:

let elements = ["The Perfect Apps", "Soft Boiled", "Medium Boiled", "Hard Boiled", "Scrambled","Fried", "Poached", "Rate", "Credits","Website"]

ios swift uitableview cocoa-touch
2个回答
0
投票

看起来你没有将indexPath传入你的单元格。你可能想要使用它:

let cell = tableView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomTableViewCell

此外,您可能没有注册该单元格。这个总是让我沮丧并导致无法解释的崩溃(确保它在你的viewDidLoad):

tableView.register(CustomTableViewCell.self, forCellWithReuseIdentifier: "customCell")

编辑:在意识到你正在使用笔尖之后,你可能想尝试这个作为你的寄存器单元。您可能想要进入故事板并仔细检查您的笔尖是否名为CustomTableViewCell。如果没有,请将其更改为任何名称:

let nib = UINib(nibName: "CustomTableViewCell", bundle: nil)
tableView.register(nib, forCellWithReuseIdentifier: "customCell")

0
投票

最后,我的问题是我的图像文件太大,因此需要花费太多内存才能加载。我所要做的就是降低它们的质量。

© www.soinside.com 2019 - 2024. All rights reserved.