SnapKit / SnapKit

A Swift Autolayout DSL for iOS & OS X

Home Page:https://snapkit.github.io/SnapKit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can not call the deinit method

tc1993 opened this issue · comments

commented

import UIKit
import IQKeyboardManagerSwift
import SnapKit
import RxSwift

class DSCompletInfoViewController: BaseViewController {

private lazy var titleLabel: UILabel = {
    let label: UILabel = UILabel()
    label.textColor = .black
    label.font = UIFont.appSystemFont(size: 36, weight: .bold)
    label.text = "Please fill in your information"
    label.numberOfLines = 0
    return label
}()

private lazy var titleLabel2: UILabel = {
    let label: UILabel = UILabel()
    label.textColor = .black
    label.font = UIFont.appSystemFont(size: 16, weight: .medium)
    label.text = "Later on, you can modify your favorite swimming stars and swimming experiences on the editing information page"
    label.numberOfLines = 0
    return label
}()

private lazy var titleLabel3: UILabel = {
    let label: UILabel = UILabel()
    label.textColor = .black
    label.font = UIFont.appSystemFont(size: 18, weight: .bold)
    label.text = "The most admired swimmer"
    label.numberOfLines = 0
    return label
}()

private lazy var titleLabel4: UILabel = {
    let label: UILabel = UILabel()
    label.textColor = .black
    label.font = UIFont.appSystemFont(size: 18, weight: .bold)
    label.text = "Swimming experience"
    label.numberOfLines = 0
    return label
}()

private lazy var textView1: IQTextView = {
    let textView: IQTextView = IQTextView()
    textView.textColor = .black
    textView.font = UIFont.appSystemFont(size: 14, weight: .medium)
    textView.placeholder = "Please write down your favorite swimmer"
    return textView
}()

private lazy var textView2: IQTextView = {
    let textView: IQTextView = IQTextView()
    textView.textColor = .black
    textView.font = UIFont.appSystemFont(size: 14, weight: .medium)
    textView.placeholder = "Please write down the reason why you like swimming"
    return textView
}()

private lazy var bottomButton: UIButton = {
    let button: UIButton = UIButton.init(type: .custom)
    button.addTarget(self, action: #selector(bottomButtonClick), for: .touchUpInside)
    button.backgroundColor = UIColor.init(hexString: "#FFB344")
    button.tc.setCorner(.allCorners, radius: 27)
    button.setTitle("Submit", for: .normal)
    button.titleLabel?.font = UIFont.appSystemFont(size: 25, weight: .bold)
    button.setTitleColor(.white, for: .normal)
    return button
}()


override func viewDidLoad() {
    super.viewDidLoad()

    initUI()
    // Do any additional setup after loading the view.
}


private func initUI(){
    
    let contentView: UIView = UIView.init()
    contentView.backgroundColor = .white
    view.addSubview(contentView)
    contentView.snp.makeConstraints { make in
        make.left.top.right.equalToSuperview()
        make.height.equalTo(540)
    }
    
    contentView.addSubview(titleLabel)
    titleLabel.snp.makeConstraints { make in
        make.top.equalToSuperview().inset(68)
        make.left.right.equalToSuperview().inset(17)
    }
    
    contentView.addSubview(titleLabel2)
    titleLabel2.snp.makeConstraints { make in
        make.top.equalTo(titleLabel.snp.bottom).offset(10)
        make.left.right.equalToSuperview().inset(17)
    }
    
    contentView.addSubview(titleLabel3)
    titleLabel3.snp.makeConstraints { make in
        make.top.equalTo(titleLabel2.snp.bottom).offset(22)
        make.left.right.equalToSuperview().inset(17)
    }
    
    contentView.addSubview(textView1)
    textView1.snp.makeConstraints { make in
        make.top.equalTo(titleLabel3.snp.bottom).offset(8)
        make.left.right.equalToSuperview().inset(17)
        make.height.equalTo(60)
    }
    
    contentView.addSubview(titleLabel4)
    titleLabel4.snp.makeConstraints { make in
        make.top.equalTo(textView1.snp.bottom).offset(5)
        make.left.right.equalToSuperview().inset(17)
    }
    
    contentView.addSubview(textView2)
    textView2.snp.makeConstraints { make in
        make.top.equalTo(titleLabel4.snp.bottom).offset(8)
        make.left.right.bottom.equalToSuperview().inset(17)
    }
    
    self.view.addSubview(bottomButton)
    bottomButton.snp.makeConstraints {  make in

        make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).inset(26)
        make.left.right.equalToSuperview().inset(25)
        make.height.equalTo(54)
    }

}

@objc func bottomButtonClick(){
    UserLoginViewModelMannager.shared.loginRelay.accept(.login)
}

deinit{
    RRLog.SEDebugPrint("deinit DSCompletInfoViewController")
}

}

if use self in closures the viewcontroller‘s deinit can not called。

It will be fine when changed to this

    self.view.addSubview(bottomButton)
    bottomButton.snp.makeConstraints { [weak self] make in
        guard let self = self else {return}
        make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).inset(26)
        make.left.right.equalToSuperview().inset(25)
        make.height.equalTo(54)
    }