0

I'm getting NSContiguousString leak on Instruments in a ViewController which has only UITableView and a UINavigationBar. When viewController appears texts on UITableViewCells doesn't shown, only blank cells.

If I change it to;

cell.textLabel?.text = NSString(string: dataSource[indexPath.row]) as String

Texts seen on cells.

Controller Class:

class FirstSupportedServicesViewController: BaseViewController {

let bTableView = UITableView()
let dataSource = ["Cell Text 1","Cell Text 2"]
override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    bTableView.delegate = self
    bTableView.dataSource = self
    bTableView.frame = self.view.frame
    bTableView.register(BaseCell.self, forCellReuseIdentifier: "SupportedServicesBaseCell")
    bTableView.tableFooterView = UIView()

    //Prevent TableView Scroll Bug
    if #available(iOS 11.0, *) {
        bTableView.contentInsetAdjustmentBehavior = .never
    } else {
        // Fallback on earlier versions
    }

    self.view.addSubview(bTableView)

    let leftButton = UIBarButtonItem(title: "< Geri", style: .plain, target: self, action: #selector(self.backBtnTapped))
    self.navigationItem.leftBarButtonItem = leftButton

}

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

@objc func backBtnTapped(){
    self.dismiss(animated: true, completion: nil)
}}
extension FirstSupportedServicesViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath:  IndexPath) -> CGFloat{
        return 44
}
}

extension FirstSupportedServicesViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 2
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "SupportedServicesBaseCell", for: indexPath) as! BaseCell
    cell.textLabel?.text = dataSource[indexPath.row]

    return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let controller = SupportedServicesViewController()
    self.navigationController?.pushViewController(controller, animated: true)

    tableView.deselectRow(at: indexPath, animated: true)

}

}

Custom TableView Cell:

class BaseCell: UITableViewCell {

let cellText: UILabel = {
    let label = UILabel()
    label.textColor = UIColor.black
    label.font = Fonts.font
    label.adjustsFontSizeToFitWidth = true

    return label
}()

override init(style: UITableViewCellStyle, reuseIdentifier: String?){
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    setupViews()
}

func setupViews() {
}
required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
}

enter image description here

enter image description here

enter image description here

enter image description here

Emre Önder
  • 2,408
  • 2
  • 23
  • 73
  • Have you read this post https://stackoverflow.com/questions/50306683/memory-leaks-when-assigning-text-to-uilabel-ios-swift-4-xcode9#comment87644156_50306683? – trungduc Jul 11 '18 at 11:17
  • Yes. I even discuss this with the post writer but we can't find any solution. – Emre Önder Jul 11 '18 at 11:19

0 Answers0