In my current project i have detail view that shows a specific record from my table view. I have the following labels
@IBOutlet weak var vacationImageView: UIImageView!
@IBOutlet weak var percentSaved: UILabel!
@IBOutlet weak var cost: UILabel!
@IBOutlet weak var saved: UILabel!
@IBOutlet weak var circleProgressView: CircularProgressView!
@IBOutlet weak var daysDepart: UILabel!
I call a popover that I want to send the current text value of saved to my popup, allow the user to edit it and send it back to the view. Here is my popover call.
@IBAction func addPopover(sender: UIView) {
let savingsInformationViewController = storyboard?.instantiateViewControllerWithIdentifier("SavingsAddPopover") as UIViewController
savingsInformationViewController.modalPresentationStyle = .Popover
savingsInformationViewController.preferredContentSize = CGSizeMake(200, 200)
let popoverController = savingsInformationViewController.popoverPresentationController
popoverController?.sourceView = sender
popoverController?.permittedArrowDirections = .Any
popoverController?.delegate = self
presentViewController(savingsInformationViewController, animated: true, completion: nil)
}
I would have thought I could reference the data object from the popover but can't..at least not the way I'm thinking.
class ViewController: UIViewController,SavingViewControllerDelegate,UIPopoverPresentationControllerDelegate{
@IBOutlet var labelText: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func buttonPopOverClick(sender: UIButton)
{
let savingsInformationViewController = storyboard?.instantiateViewControllerWithIdentifier("SavingsAddPopoverVC") as SavingViewController
savingsInformationViewController.delegate = self
savingsInformationViewController.strSaveText=labelText.text
savingsInformationViewController.modalPresentationStyle = .Popover
if let popoverController = savingsInformationViewController.popoverPresentationController {
popoverController.sourceView = sender
popoverController.sourceRect = sender.bounds
popoverController.permittedArrowDirections = .Any
popoverController.delegate = self
}
presentViewController(savingsInformationViewController, animated: true, completion: nil)
}
func saveText(strText: NSString) {
labelText.text=strText
}
// MARK: - UIPopoverPresentationControllerDelegate
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle {
return .FullScreen
}
func presentationController(controller: UIPresentationController!, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController! {
return UINavigationController(rootViewController: controller.presentedViewController)
}
}
protocol SavingViewControllerDelegate
{
func saveText(var strText : NSString)
}
class SavingViewController: UIViewController {
@IBOutlet var textField: UITextField!
var delegate : SavingViewControllerDelegate?
var strSaveText : NSString!
override func viewDidLoad() {
super.viewDidLoad()
textField.text = strSaveText
// Do any additional setup after loading the view.
}
@IBAction func buttonDone(sender: UIButton)
{
if (self.delegate) != nil
{
delegate?.saveText(textField.text)
self.dismissViewControllerAnimated(true, nil)
}
}
}
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