UITableView
とUITableViewCell
を生成することはできますが、私の動作は正しく動作していません。私のユースケースは、私が参考にthis質問を使用していたと私は何をしないのです再帰的UITableViewCellボタンアクション
uncesscessfulた this video
に似ているのですか?何かが関連して速くなる?
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var categories = ["foo", "bar"]
func logAction(sender: UIButton!){
print("HIT BUTTON YO")
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.categories.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:CustomCell = tableView.dequeueReusableCell(withIdentifier: "categories", for: indexPath) as! CustomCell
cell.label.text = categories[indexPath.row]
let button = cell.button
button?.tag = indexPath.row
button?.addTarget(self, action: #selector(self.logAction), for: .touchUpInside)
return(cell)
}
}
class CustomCell: UITableViewCell {
@IBOutlet weak var button: UIButton!
@IBOutlet weak var label: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
//Configure view for selected state
}
}
クラッシュログが何を言うのでしょうか? –
それはまったくクラッシュしません....私のテーブル上のボタンをクリックすると、何も起こらない.... 'tableView(_ tableView:UITableView、cellForRowAt indexPath:IndexPath)'を試してみた –