2016-11-24 3 views
0

ボタンが正しく機能しているため、タップで無効にする方法がわかりません。私がsender.tagを参照するようなaddSomething(送信側:UIButton)関数から参照できるかどうかはわかりません。 助けてくれてありがとう。私はこのことを願っていますすぐにタップするとテーブルビューのセルボタンが無効になる

class ViewController: UIViewController { 
    var tappedButtonsTags = [Int]() 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let myCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ExploreCell 

     // Configure the cell... 
     myCell.configureCell(teams[indexPath.row]) 

     myCell.addSomethingButton.tag = indexPath.row 

     // here is the check: 
     if tappedButtonsTags.contains(indexPath.row) { 
      myCell.addSomethingButton.enabled = false 
     } else { 
      myCell.addSomethingButton.addTarget(self, action: #selector(self.addSomething), forControlEvents: .TouchUpInside) 
      myCell.addSomethingButton.enabled = true 
     } 

     //disable cell clicking 
     myCell.selectionStyle = UITableViewCellSelectionStyle.None 

     return myCell 
    } 

    // I just Implemented this for demonstration purposes, you can merge this one with yours :) 
    func addSomething(button: UIButton) { 
     tappedButtonsTags.append(button.tag) 
     tableView.reloadData() 
     // ... 
    } 
} 

を:あなたがする必要がある何

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let myCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ExploreCell 

    // Configure the cell... 
    myCell.configureCell(teams[indexPath.row]) 

    myCell.addSomethingButton.tag = indexPath.row 
    myCell.addSomethingButton.addTarget(self, action: #selector(self.addSomething), forControlEvents: .TouchUpInside) 

    myCell.addSomethingButton.enabled = true 

    //disable cell clicking 
    myCell.selectionStyle = UITableViewCellSelectionStyle.None 

    return myCell 
} 

答えて

1

は、このタグ(現在indexPath.row)のボタンがタップされたかどうかを確認するために、アレイ内のすべてのタップボタンを格納することです助けてくれた。

+0

すべての作業をしていただきありがとうございますが、それを配置した後、ボタンをクリックした後でもテーブルビューが読み込まれない場合にのみチェックを行うようです。 – user3712837

+0

それは簡単です、答えはボタンのターゲットに "tableView.reloadData()"を追加することによって編集されました –

+0

ああ、ありがとう!それは素晴らしい仕事でした!私は既に追加されたデータベースをチェックする前に配列をループしています。彼らは素晴らしい仕事をしました。 – user3712837

関連する問題