TableViewHeader笔尖按钮不起作用

时间:2017-08-14 06:39:34

标签: ios swift uitableview

我面临的问题是我正在从tableView控制器中的nib文件加载头文件。我在nib文件中有所有iBoutlet和Actions。我的标题已成功加载到标题中,但该按钮未执行任何操作。代码附在下面

  1. TableView控制器:Click Here
  2. Nib HeaderView:[Click Here](https://www.dropbox.com/s/683m7ayfpahpopt/Screen%20Shot%202017-08-14%20at%2011.12.46%20AM.png?dl=0
  3. 以下是HeaderView控制器的代码:

    import UIKit
    
    
    class HeaderFooterView: UITableViewHeaderFooterView {
    
        @IBOutlet weak var reviewBtn: UIButton!
        @IBOutlet weak var vendorImage: UIImageView!
    
        @IBOutlet weak var vendorName: UILabel!
    
        @IBOutlet weak var vendorCharges: UILabel!
        @IBOutlet weak var customView: UIView!
    
        var view: UIView!
    
    
    //    @IBAction func reviewBtn(_ sender: Any) {
    //        
    //        print("WriteReview Pressed")
    //        let object = CurrentVendorViewController()
    //        object.dismissMyAlertView(view: view)
    //        
    //       // customAlertView.isUserInteractionEnabled = false
    //    }
    //   
    
    
    
    }
    

    这是我的TableView控制器:

    import UIKit
    
    class CurrentVendorViewController: UIViewController , UITableViewDelegate,UITableViewDataSource  , UIGestureRecognizerDelegate{
    
        @IBOutlet weak var myTableView: UITableView!
    
    
        @IBOutlet weak var giveReviewField: UITextView!
        @IBOutlet weak var reviewStar1: UIButton!
        @IBOutlet weak var reviewStar2: UIButton!
        @IBOutlet weak var reviewStar3: UIButton!
        @IBOutlet weak var reviewStar4: UIButton!
    
        @IBOutlet weak var reviewStar5: UIButton!
    
        @IBOutlet weak var customAlertView: UIView!
    
        @IBOutlet weak var menuBtn: UIBarButtonItem!
        var reviewerName = ["Abdullah" , "David" , "Brock" , "John" , "Mellisa"]
        var review = ["Best Cartpenter" , "Best Plumber" , "Average work" , "Excellent Work" , "Great WOrk Done by Aziz"]
    
    
    
        var blurEffectView = UIVisualEffectView()
        var flag = false
        var header : HeaderFooterView!
        var lpgr: UILongPressGestureRecognizer!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            if !(flag){
                myTableView.delegate = self
                myTableView.dataSource = self
    
                //register the header view
    
                let nib = UINib(nibName: "alertView", bundle: nil)
                myTableView.register(nib, forHeaderFooterViewReuseIdentifier: "HeaderFooterView")
    
                myTableView.separatorInset.left = 150
                myTableView.separatorInset.right = 150
    
    
                //Hiding Alert View
                customAlertView.isHidden = true
    
    
    
                 lpgr = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
                //addTarget(self, action: #selector(handleLongPress),for: .valueChanged)
    
                lpgr.minimumPressDuration = 0.01
                lpgr.delaysTouchesBegan = true
                lpgr.delegate = self
               // customCollectionView.addGestureRecognizer(lpgr)
                //self.tableView.tableHeaderView.addGestureRecognizer(lpgr)
    
    
    
    
            }
    
    
    
    
        }
    
        func handleLongPress(gestureReconizer: UILongPressGestureRecognizer)
        {
            if gestureReconizer.state != UIGestureRecognizerState.ended {
                return
            }
    
            let p = gestureReconizer.location(in: header)
            print("P: \(p)")
    
        }
    
    
        func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    
            print("Height ForHeader")
    
            let cell = self.myTableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderFooterView") as! HeaderFooterView
    
            //let height = CGFloat(cell.customView.frame.height)
            //let height = 100
    
    
            return CGFloat(1)
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
        func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
            print("Header Appeared: \(tableView.tableHeaderView)")
            //tableView.tableHeaderView?.isUserInteractionEnabled = true
    
             self.header.isUserInteractionEnabled = true
    
    
        }
    
    
        func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
            // Here, we use NSFetchedResultsController
            // And we simply use the section name as title
            //let currSection = fetchedResultsController.sections?[section]
            //let title = currSection!.name
    
            // Dequeue with the reuse identifier
    
            print("I am in view for header")
    
    
            let cell = self.myTableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderFooterView")
            header = cell as! HeaderFooterView
    
            tableView.tableHeaderView = header
           // header.addGestureRecognizer(lpgr)
    
    
            self.header.reviewBtn.addTarget(self, action:#selector(clicked(_:)), for: .touchUpInside)
    
    
            //header.reviewBtn.isUserInteractionEnabled = true
    
    
            //header..text = "YESS"
    
            header.vendorName.text = "Mr. Electric"
    
            /*Image Settings*/
            header.vendorImage.layer.borderWidth = 2
            header.vendorImage.layer.borderColor = UIColor(red: 83/255.0, green: 39/255.0, blue: 119/255.0, alpha: 1.0).cgColor
            header.vendorImage.layer.cornerRadius = header.vendorImage.frame.size.height/2
    
            header.vendorImage.layer.masksToBounds = false
            header.vendorImage.clipsToBounds = true
            header.reviewBtn.layer.cornerRadius = 5
    
            //header.view = customAlertView
    
            //print("HeaderView: \(header.view) ,,,,, Custom: \(customAlertView)")
    
            return cell
        }
    
    
    
        // MARK: - Table view data source
    
        func numberOfSections(in tableView: UITableView) -> Int {
            // #warning Incomplete implementation, return the number of sections
            return 1
        }
    
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            // #warning Incomplete implementation, return the number of rows
            return reviewerName.count
        }
    
    
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! VendorReviewsCustomCell
    
            cell.reviewerName.text = reviewerName[indexPath.row]
            cell.reviewText.text = review[indexPath.row]
    
            return cell
        }
    
        @IBAction func backBtn(_ sender: Any) {
            self.navigationController?.popViewController(animated: true)
        }
    
    
        @IBAction func requestService(_ sender: Any) {
            performSegue(withIdentifier: "reqService_segue", sender: self)
        }
    
        func clicked(_ sender: Any) {
    
            print("DETECT ..........")
        }
    
        /*
        // MARK: - Navigation
    
        // In a storyboard-based application, you will often want to do a little preparation before navigation
        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            // Get the new view controller using segue.destinationViewController.
            // Pass the selected object to the new view controller.
        }
        */
    
        @IBAction func submitReview(_ sender: Any) {
    
            print("Submitted")
            customAlertView.isHidden = true
            removeBlurEffect()
            flag = false
        }
    
        @IBAction func dismissAlertView(_ sender: Any) {
    
            print("X button")
            customAlertView.isHidden = true
            removeBlurEffect()
            flag = false
        }
    
        @IBAction func giveRating(_ sender: UIButton) {
        }
    
    
        func removeBlurEffect(){
    
            customAlertView.transform = CGAffineTransform.identity
            UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {() -> Void in
                self.customAlertView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
            }, completion: {(finished: Bool) -> Void in
                // do something once the animation finishes, put it here
                self.blurEffectView.removeFromSuperview()
    
            })
        }
    
    
        func dismissMyAlertView(view: UIView)  {
            print("delegate fired")
    
            print("View: \(view)")
    
            flag = true
            customAlertView = view
            customAlertView.isHidden = false
    
            customAlertView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
            UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {() -> Void in
                self.customAlertView.transform = CGAffineTransform.identity
            }, completion: {(finished: Bool) -> Void in
                // do something once the animation finishes, put it here
    
                let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight)
    
                self.blurEffectView = UIVisualEffectView(effect: blurEffect)
                self.blurEffectView.frame = self.view.bounds
                self.blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    
                self.blurEffectView.alpha = 0.4
                self.myTableView.addSubview(self.blurEffectView)
    
            })
    
    
        }
    
    
    }
    

    在viewForHeaderInSection中,我检查了nib文件中的所有属性是否为空值。但仍然审查按钮不起作用。请帮帮我

0 个答案:

没有答案