简体   繁体   中英

Button action in custom cell

I didn't find any normal solution, how to detect click on button or other actions in UIViewController that have @IBOutlet weak var tableView:UITableView! with custom cell.

My cell:

class CartTableViewCell: UITableViewCell, FloatRatingViewDelegate {
    @IBOutlet var floatRatingView: FloatRatingView!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code 
        self.floatRatingView.delegate = self
    }

    // MARK: FloatRatingViewDelegate

    func floatRatingView(ratingView: FloatRatingView, didUpdate rating: Float) {


    }
}

How to access in floatRatingView method to variables from my view ??

There are two ways this can be done.

The first is using interface builder and there is a guide here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_connections/chapters/CreatingAction.html

The other option is to do this programatically

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code 
    self.floatRatingView.delegate = self

    myButton.addTarget(self, action: "myButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
}

func myButtonTapped(sender: UIButton) {
    floatRatingView(someView, didUpdate: someRating)
}

func floatRatingView(ratingView: FloatRatingView, didUpdate rating: Float) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM