2017-09-22 14 views
0

나는이 해답을 찾고 있었지만 찾지 못했습니다. 컬렉션보기 위에 sectionHeader가 있습니다. 헤더에 버튼을 추가했지만 기능이 실행되지 않습니다. 1 분 빨리 살펴보고 나를 도와주는 마음?UIButton 안쪽 머리글이 작동하지 않습니다.

import UIKit 
class SearchHeader: UICollectionViewCell { 

    let filterLbl: UILabel = { 
     let label = UILabel() 
     label.text = "Filter" 
     label.font = UIFont.systemFont(ofSize: 18) 
     return label 
    }() 

    let addFilterBtn: UIButton = { 
     let button = UIButton(type: .system) 
     button.setImage(#imageLiteral(resourceName: "addFilter").withRenderingMode(.alwaysOriginal), for: .normal) 
     button.addTarget(self, action: #selector(handleAddFilter), for: .touchUpInside) 
     return button 

    }() 

    func handleAddFilter(button: UIButton) { 
     print(1234) 
    } 

    override init(frame: CGRect) { 
     super.init(frame: frame) 

     backgroundColor = .white 

     addSubview(filterLbl) 
     addSubview(addFilterBtn) 

     filterLbl.anchor(top: topAnchor, left: leftAnchor, bottom: bottomAnchor, right: nil, paddingTop: 10, paddingLeft: 10, paddingBottom: 10, paddingRight: 0, width: 0, height: 0) 
     addFilterBtn.anchor(top: topAnchor, left: filterLbl.rightAnchor, bottom: bottomAnchor, right: nil, paddingTop: 10, paddingLeft: 5, paddingBottom: 10, paddingRight: 0, width: 0, height: 0) 
    } 

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

} 

답변

0

답변을 찾았습니다. 당신이 게으른 VAR

로하게 변경해야 할 몇 가지 이유

lazy var addFilterBtn: UIButton = { 
    let button = UIButton(type: .system) 
    button.setImage(#imageLiteral(resourceName: "addFilter").withRenderingMode(.alwaysOriginal), for: .normal) 
    button.addTarget(self, action: #selector(handleAddFilter), for: .touchUpInside) 
    return button 

}()