我table view
在一个全新的项目中有一个正常的,没有额外的代码。在我的故事板中,我有 2 个视图控制器和一个navigation controller
嵌入到First Controller
. 在First Controller
我有一个带有按钮和标签的表格视图。我已经在情节提要中segue
从按钮到第二个控制器。cell
我想知道的是我什么时候deinit
会先被调用controller
,而不是被调用。我设置了断点,但似乎没有任何效果。
当我segue
回到它工作时second
,因为是。但是我们需要做什么才能在第一个控制器中运行?我需要先从吗?还是我需要明确指定其他地方?first
second controller
controller
popped
deinit
pop
controller
stack
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")
}
}