swift 프록시 사용 방법

1270 단어 swift
4
import UIKit

@objc protocol TestCellDelegate : class {
    //     
    @objc optional func cellTestButtonClick(index: NSInteger)
    // viewController    ,      
    func buttonClick()
}

class TestCell: UITableViewCell {
    
    var delegate: TestCellDelegate?
    var testButton = UIButton()
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.testButton = UIButton.init(type: UIButtonType.custom)
        self.testButton.frame = CGRect(x: 10, y: 10, width: 80, height: 40)
        self.testButton.setImage(UIImage.init(name: ""), for: UIControlState.normal)
        self.testButton.addTarget(self, action:#selector(testButtonClick), for: UIControlEvents.touchUpInside)
        self.addSubview(self.testButton)
    }
    
    var model : S_CollectDataModel? {
        didSet {
        }
    }
    
    func testButtonClick(button: UIButton) {
        if (self.delegate != nil) {
            self.delegate?.cellTestButtonClick!(index: self.tag)
        }
    }
}
view Controller에서 프로토콜 준수, 에이전트 설정, 에이전트 호출 방법, 구체적인 코드는 쓰지 않음

좋은 웹페이지 즐겨찾기