Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Xcode 9 Swift 4因内存问题而终止(返回单元格)_Ios_Swift_Uitableview_Cocoa Touch - Fatal编程技术网

Ios Xcode 9 Swift 4因内存问题而终止(返回单元格)

Ios Xcode 9 Swift 4因内存问题而终止(返回单元格),ios,swift,uitableview,cocoa-touch,Ios,Swift,Uitableview,Cocoa Touch,现在我知道还有很多其他的问题与同样的问题,然而,没有一个是崩溃点我的 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! CustomTableViewCell cell

现在我知道还有很多其他的问题与同样的问题,然而,没有一个是崩溃点我的

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"]

看起来您没有将indexPath传递到单元格中。您可能希望改用此选项:

let cell = tableView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomTableViewCell
此外,您可能没有注册该单元格。这一个总是让我绊倒,并导致无法解释的崩溃(确保它在您的
viewDidLoad
中):

编辑: 在意识到您正在使用nib后,您可能希望尝试将其作为您的注册单元。您可能希望进入故事板并仔细检查nib是否命名为CustomTableViewCell。如果不是,则将其更改为任何名称:

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

最后,我的问题是,我的图像文件太大,因此占用了太多的内存。我所要做的就是降低它们的质量

你能显示数组元素吗?我已经添加了数组@Sh_khan请不要发布代码的图片。我没有任何名称CustomCell,这应该是什么?(我有识别码,但不是真的。)@mattpid道歉。我已将其重命名为您使用的正确单元格(CustomTableViewCell)。我已经编辑了上面的代码。我还有一个错误。在主要问题中附上照片。为胜利干杯help@MattPidd您希望viewDidLoad中的所有内容都位于super.viewDidLoad()下面。顺便问一下,您能否确认CustomTableViewCell是一个实际的类?i、 e类CustomTableViewCell:UITableViewCell{}是的,它是另一个视图控制器中的一个类,已确认。这有区别吗?在主问题中添加了另一个图像以获取帮助。我正在尝试在watchApp中调试此错误。在您的情况下,您如何确定错误发生的位置?这是愚蠢的运气,还是你发现了什么可以帮我找到问题的地方?这真的很幸运,因为我只是在等待回复时重新制作了一些图形,并意识到我的图像是屏幕上小图片的大文件。一旦我缩小了尺寸,效果很好!你是如何成功的。让我恼火的是,苹果用这样的信息构建代码,但却没有专业性来提供支持文档。我的意思是,“记忆问题”到底有多缺乏信息?我完全没有攻击性
let nib = UINib(nibName: "CustomTableViewCell", bundle: nil)
tableView.register(nib, forCellWithReuseIdentifier: "customCell")