请在每次点击内存增加的单元格时,在表视图中使用标识符执行segue有问题didSelectRow方法
以下是我的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// firstly i need to check if edit button is true so i can select cell
if isShowToolBar {
// her for hold selected index
let cell = tableView.cellForRow(at: indexPath) as? MovieDownloadedTableViewCell
if let cell = cell {
cell.movieCheckMarkImageView.isHidden = false
cell.movieEmptyCircleImageView.isHidden = true
operationDocumentDirectoryObject.dictionaryHoldIndexCellForDisplayWhichCellSelected.updateValue(indexPath.row, forKey: indexPath.row)
// start hold URL
operationDocumentDirectoryObject.dictionaryForHoldURLSelected.updateValue(operationDocumentDirectoryObject.arrayOfMovieURL![indexPath.row], forKey: indexPath.row)
}// end the if let cell
}else{
// her for show the content folder
let cell = tableView.cellForRow(at: indexPath) as? MovieDownloadedTableViewCell
if let cell = cell {
if cell.fetchURL!.pathExtension == "" {
performSegue(withIdentifier: "ShowFolder", sender: indexPath.row)
}else{
// playing the video
performSegue(withIdentifier: "PlayingMovie", sender: cell.fetchURL!.lastPathComponent)
}// end the if for check path extenstion
}// end the if let cell
cell = nil
}// end the if for the isShowToolbar
}
上述方法在执行segue 时出现内存泄漏,并导致内存增加(如果是cell.fetchURL!.pathExtension =="")也会造成内存泄漏
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MoveFile" {
if let destination = segue.destination as? MoveMovieViewController {
destination.operationDocumentDirectoryObject.dictionaryForHoldURLSelected = self.operationDocumentDirectoryObject.dictionaryForHoldURLSelected
}
}else if segue.identifier == "ShowFolder" {
if let destination = segue.destination as? ShowContentFolderMovieViewController {
if let fetchIndex = sender as? Int {
destination.operationDocumentDirectory.folderName = self.operationDocumentDirectoryObject.arrayOfMovieURL![fetchIndex].lastPathComponent
}
}
}else if segue.identifier == "PlayingMovie" {
// make an object for the playing video view controller
if let destination = segue.destination as? PlayingMovieViewController {
if let movieName = sender as? String {
destination.operationDocumentDirectory.movieName = movieName
}
}
}// end the condition for the segue
}
虽然deinit在视图控制器中调用成功,但我仍然在泄漏并增加内存
请帮助我的错误代码是什么?
非常感谢
答案 0 :(得分:0)
我怀疑你的代码中某处有一个强大的引用循环 - 尽管如此,据我所知,你所发布的内容并非如此。但是,你说你的deinit被成功调用了。您是否检查过您正在调用的所有视图控制器的deinits是否在预期的时间被调用(例如当您解除PlayingMovieViewController或ShowContentFolderMovieViewController时)?观察用于deinit打印语句的xcode调试控制台以检查内存中的适当版本是最好的方法。你的内存泄漏可能来自其他地方。您应该在代码中的其他地方寻找强引用(可能是代理人持有发件人对象?)。