我在UITableView中使用UIAlertController。它在tableview.delegate = self附近返回nil值。這裏alertC是提供警報的功能。我在按下按鈕時從tableViewCell調用alertC函數。UITableView中的UIAlertController返回無
class AdminPlaces: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
private var placeNames = [String]()
override func viewDidLoad() {
super.viewDidLoad()
self.getDataFromFirebase {
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.reloadData()
}
func alertC() {
let ac = UIAlertController(title: "Delete", message: "Are you sure to delete the place", preferredStyle: .alert)
let yesAction = UIAlertAction(title: "Yes", style: .default, handler: nil)
let noAction = UIAlertAction(title: "No", style: .cancel, handler: nil)
ac.addAction(yesAction)
ac.addAction(noAction)
self.present(ac, animated: true, completion: nil)
}
}
class AdminPlacesCell: UITableViewCell {
@IBOutlet weak var placeName: UILabel!
@IBOutlet weak var delete: UIButton!
@IBOutlet weak var edit: UIButton!
override func awakeFromNib() {
edit.alpha = 0
delete.alpha = 0
}
func configure(place: String) {
placeName.text = place
}
func showButtons() {
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseIn, animations: {
self.edit.alpha = 1
self.delete.alpha = 1
}, completion: nil)
}
@IBAction func onEditClicked(_ sender: Any) {
}
@IBAction func onDeleteClicked(_ sender: Any) {
let adminPlaces = AdminPlaces()
adminPlaces.alertC()
}
}
我不明白是什麼問題。爲什麼它返回零附近tableView.delegate = self?什麼是待辦事項的正確方法?
在此先感謝
請檢查此鏈接,因爲它解決了我的問題。 [鏈接](http://stackoverflow.com/a/34911172/6223683) –