table view
追加のコードなしで、完全に新しいプロジェクトに法線があります。私のストーリーボードには、2 つのビュー コントローラーと へのnavigation controller
埋め込みがありFirst Controller
ます。First Controller
ボタンとラベルを含むテーブルビューがあります。ストーリーボードのボタンから2番目のコントローラーに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
}
}
2 番目のコントローラー:
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")
}
}