我需要帮助调试一个性能问题。
我有两个ViewController A
和B
。 A
点击B
时按下UIButton
。 B
包含UITableView
。
当我在UIButton
中单击A
时,UI冻结1-2秒,然后出现B
。当我从UITableView
中删除B
时,推送会顺利进行。
建立单元格(我将标签留空):
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()
}
建立表格视图
tableView = UITableView()
tableView.customize(cellClasses: [FeedWallCell.self])
view.addSubview(tableView)
tableView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
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)
}
}
简单推送需要600毫秒以上的时间
iOS11,Xcode9,iPhone6