我已经通过few of these tutorial,我似乎无法通过按钮点击调用我的功能。我跟着这个人的tutorial,但没有任何工作。行动按钮不工作在UITable
我tableView
目前正在工作很好,所有我现在正在做的是添加一个按钮,所以我可以传递数据到另一个视图,但我的按钮单击不调用它的功能。
//class IncomeFeedCell: UITableViewCell:
@IBOutlet var weak button: UIButton!
查看位指示:
// class IncomeFeedVC: UIViewController, UITableViewDelegate, UITableViewDataSource:
// viewDidLoad:
tableView.delegate = self
tableView.dataSource = self
// cellForRowAt indexPath
let cell = self.tableView.dequeueReusableCell(withIdentifier: "IncomeFeedCell") as! IncomeFeedCell
cell.button.tag = indexPath.row
cell.button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
cell.configureCell(income: income)
return cell
现在的功能挖掘时要调用:
func buttonPressed(){
print("Tapped")
}
模拟器:
我错过了简单的事情吗?
编辑:
道歉所有谁,并试图帮助和得到downvoted,因为我离开了更多的重要信息。所有这一切都在我的viewDidLoad
在IncomeFeedVC
:
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
DataService.ds.REF_INCOMES.queryOrdered(byChild: "date").observe(.value, with: { (snapshot) in
/**
* Sorting the object before looping over
* Info here: http://stackoverflow.com/questions/41416359/sort-firebase-data-with-queryordered-by-date
*/
guard let incomeSnap = snapshot.value as? [String:AnyObject] else{
return
}
let sorted = incomeSnap.sorted{($0.0.value["date"] as! Double) > ($0.1.value["date"] as! Double)}
for snap in sorted {
if let incomeDict = snap.value as? [String: AnyObject] {
let key = snap.key
let income = Income(incomeId: key, incomeData: incomeDict)
self.incomes.append(income)
}
}
self.tableView.reloadData()
})
@HimanshuMoradiya请问是什么和在哪里? – Sylar
cell.button.addTarget(self,action:#selector(buttonPressed),for:.touchUpInside)this line and func buttonPressed(){ print(“Tapped”) } funcation –
您的问题不清楚。确切的问题是什么?当你点击按钮会发生什么? – rmaddy