首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用表视图deinit

未调用表视图deinit
EN

Stack Overflow用户
提问于 2017-12-10 23:44:45
回答 0查看 866关注 0票数 1

我在一个全新的项目中有一个普通的table view,没有额外的代码。在我的故事板中,我有两个视图控制器和一个嵌入到First Controller中的navigation controller。在First Controller中,我有一个带有按钮和标签的表视图。我已经从cell按钮给了故事板中的第二个控制器segue

我想知道的是,当第一个controller调用我的deinit时,它不会被调用。我设置了断点,但似乎什么都不起作用。

当我从second segue回到first时,它适用于second controller,因为controllerpopped。但是我们需要做什么才能在第一个控制器中运行deinit呢?我是否也需要从stack pop first controller?或者我需要在其他地方显式地指定nil

请帮我理解一下背后的正确概念?在这一点上,请引导我正确的方向。

代码-:

代码语言:javascript
复制
import UIKit

class ViewController: UIViewController {

    // CELL DATA ARRAY

     var data = [0,0,0,0,0,0,0,0,0,0]

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        // INITIALIZE total tap ARRAY WITH INDEX 0
    }

    deinit {
        print("Deleted")
    }
}

// TABLE VIEW METHODS

extension ViewController:UITableViewDelegate,UITableViewDataSource{

    // NUMBER OF ROWS
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    // number of sections
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }

    // Cell for row

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        // deque cell
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
        cell.customLabel.text = "Total taps : \(String(data[indexPath.row]))"
        // CALL BACK BUTTON
        return cell
    }

}

自定义单元格-:

代码语言:javascript
复制
import UIKit

class CustomCell: UITableViewCell {

    // Outlets

    @IBOutlet weak var customCount: UIButton!
    @IBOutlet weak var customLabel: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    // Cell button action

    @IBAction func countTaps(_ sender: UIButton) {

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

第二个控制器-

代码语言:javascript
复制
import UIKit

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    deinit {
        print("denit")
    }
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47740470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档