我在一个全新的项目中有一个普通的table view,没有额外的代码。在我的故事板中,我有两个视图控制器和一个嵌入到First Controller中的navigation controller。在First Controller中,我有一个带有按钮和标签的表视图。我已经从cell按钮给了故事板中的第二个控制器segue。
我想知道的是,当第一个controller调用我的deinit时,它不会被调用。我设置了断点,但似乎什么都不起作用。
当我从second segue回到first时,它适用于second controller,因为controller是popped。但是我们需要做什么才能在第一个控制器中运行deinit呢?我是否也需要从stack pop first controller?或者我需要在其他地方显式地指定nil?
请帮我理解一下背后的正确概念?在这一点上,请引导我正确的方向。
代码-:
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
}
}自定义单元格-:
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
}
}第二个控制器-
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")
}
}https://stackoverflow.com/questions/47740470
复制相似问题