简体   繁体   English

自定义单元格中的按钮动作

[英]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! 我没有找到任何正常的解决方案,如何检测UIViewController中具有@IBOutlet weak var tableView:UITableView!按钮单击或其他操作@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 ?? 如何在floatRatingView方法中从我的视图访问变量?

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 首先是使用界面生成器,这里有一个指南: 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) {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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