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
}
すべての作業をしていただきありがとうございますが、それを配置した後、ボタンをクリックした後でもテーブルビューが読み込まれない場合にのみチェックを行うようです。 – user3712837
それは簡単です、答えはボタンのターゲットに "tableView.reloadData()"を追加することによって編集されました –
ああ、ありがとう!それは素晴らしい仕事でした!私は既に追加されたデータベースをチェックする前に配列をループしています。彼らは素晴らしい仕事をしました。 – user3712837