【发布时间】:2017-01-19 19:09:10
【问题描述】:
我在 UITableView 中使用 UIAlertController。它在 tableview.delegate = self 附近返回 nil 值。这里的 alertC 是呈现警报的函数。当按下按钮时,我正在从 tableViewCell 调用 alertC 函数。
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 附近返回 nil?正确的做法是什么??
提前致谢
【问题讨论】:
-
请检查此链接,因为它解决了我的问题。 link
标签: ios swift uitableview uialertcontroller tableviewcell