2

I need help with debugging one performance issue.

Overview

I have two ViewController A and B. A pushes B on UIButton click. B contains UITableView.

Problem

When I click on UIButton in A UI freezes for 1-2 sec and then B will appear. When I remove UITableView from B then push works smooth.

Implementation

building cell (I am leaving labels empty):

addCustomSelectedBackgroundColor(.ma_tintLightBlue)
backgroundColor = .clear

// container view
let containerView = UIView()
containerView.backgroundColor = .ma_white
contentView.addSubview(containerView)
containerView.snp.makeConstraints {
    $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 0.0, left: 0.0, bottom: 8.0, right: 0.0))
}

// avatar
authorAvatar = AvatarView(dimension: 46.0)
containerView.addSubview(authorAvatar)
authorAvatar.snp.makeConstraints {
    $0.leading.equalToSuperview().offset(16.0)
    $0.top.equalToSuperview().offset(10.0)
}

// date
dateLabel = UILabel()
dateLabel.font = .ma_systemFont(ofSize: 11.0)
dateLabel.textColor = .ma_textGray
containerView.addSubview(dateLabel)
dateLabel.snp.makeConstraints {
    $0.top.equalToSuperview().offset(14.0)
    $0.trailing.equalToSuperview().offset(-16.0)
}

// author info
let authorInfoView = buildAuthorInfoView()
containerView.addSubview(authorInfoView)
authorInfoView.snp.makeConstraints {
    $0.centerY.equalTo(authorAvatar.snp.centerY)
    $0.leading.equalTo(authorAvatar.snp.trailing).offset(12.0)
    $0.trailing.lessThanOrEqualTo(dateLabel.snp.leading).offset(-12.0)
}

// content
contentLabel = UILabel()
contentLabel.font = .ma_systemFont(ofSize: 14.0)
contentLabel.textColor = .ma_textBlack
contentLabel.numberOfLines = 0
containerView.addSubview(contentLabel)
contentLabel.snp.makeConstraints {
    $0.leading.equalToSuperview().offset(16.0)
    $0.trailing.equalToSuperview().offset(-16.0)
    $0.top.equalTo(authorAvatar.snp.bottom).offset(8.0)
}

// bottom bar
bottomView = PostCellBottomView()
containerView.addSubview(bottomView)
bottomView.snp.makeConstraints {
    $0.top.equalTo(contentLabel.snp.bottom).offset(20.0)
    $0.leading.equalToSuperview().offset(16.0)
    $0.trailing.equalToSuperview().offset(-16.0)
    $0.bottom.equalToSuperview()
}

building tableview

tableView = UITableView()
tableView.customize(cellClasses: [FeedWallCell.self])
view.addSubview(tableView)
tableView.snp.makeConstraints {
    $0.edges.equalToSuperview()
}

customize method for tableview

extension UITableView {

    func customize(cellClasses: [IdentifiableTableViewCell.Type] = [],
                   headerFooterClasses: [IdentifiableTableViewHeaderFooterView.Type] = [],
                   datasource: UITableViewDataSource? = nil,
                   delegate: UITableViewDelegate? = nil) {

        backgroundColor = .clear
        separatorStyle = .none
        keyboardDismissMode = .interactive

        estimatedRowHeight = 60
        rowHeight = UITableViewAutomaticDimension

        estimatedSectionHeaderHeight = 60
        sectionHeaderHeight = UITableViewAutomaticDimension

        estimatedSectionFooterHeight = 60
        sectionFooterHeight = UITableViewAutomaticDimension

        self.dataSource = datasource
        self.delegate = delegate

        register(cellClasses: cellClasses)
        register(headerFooterClasses: headerFooterClasses)
    }
}

Profiling

Simple push takes 600+ ms

enter image description here

Environment

iOS11, Xcode9, iPhone6

Kamil Harasimowicz
  • 3,534
  • 5
  • 26
  • 48

0 Answers0