I try to call the UIAlertController out of an UITableViewCell.
I have my delegate
protocol DEPFlightStripCellDelegate {
func callAlert(AlertCon: UIAlertController!)
}
whitch I called inside of my TableViewCell Class below.
class DEPFlightStripCell: UITableViewCell {
var delegate: DEPFlightStripCellDelegate?
@IBAction func changeClearedFlightLevel(sender: UIButton) {
let AddAlert: UIAlertController = UIAlertController(title: "Select Altitude", message: "", preferredStyle: .Alert)
self.delegate?.callAlert(AddAlert)
}
}
To present the view controller I set it up inside of my mainView class with DEPFlightStripCellDelegate and call the function I declare above "callAlert" to display the alert.
class mainView: UIViewController,UITextFieldDelegate, DEPFlightStripCellDelegate {
func callAlert(AlertCon: UIAlertController!) {
println("Test")
self.presentViewController(AlertCon, animated: true, completion: nil)
}
}
However the delegate return nil. Anyone have an idea why?
Your mainView instance has not been assigned as the delegate in a DEPFlightStripCell. When you instantiate that cell, usually in a table view delegate method, you should give that cell its delegate.
Something like:
class mainView: UIViewController,UITextFieldDelegate, DEPFlightStripCellDelegate {
// ...
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
as! DEPFlightStripCell
cell.delegate = self
return cell
}
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With