I want to show a popup menu and without using nib.I dont like using nib since the headache to implement delegate for a simple functionality. I succeeded using modalPresentationStyle
as a Popover
to show ViewController
as a Popover
and it works fine with the below code.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var btnShowPopOver: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showPopUP(sender: AnyObject) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popVC = storyboard.instantiateViewControllerWithIdentifier("pop")as! PopViewController
popVC.modalPresentationStyle = UIModalPresentationStyle.Popover
popVC.preferredContentSize = CGSizeMake(320, 240)
popVC.popoverPresentationController!.delegate = self
let popOverController = popVC.popoverPresentationController
popOverController!.sourceView = sender as! UIView // where to stick the bar item in which view
popOverController!.sourceRect = CGRectMake(70,30, 0, 0) //where to stick the bar
popOverController?.permittedArrowDirections = nil
self.presentViewController(popVC, animated: true, completion: nil)
}
}
extension ViewController :UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyleForPresentationController(PC: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
var controller = popoverPresentationController.presentedViewController as! PopViewController
println(" this is data from pop view controller \(controller.textField.text)")
}
}
Apple doc says
Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
I tested this on real device iphone-6 and its working fine..I am loving this Popover
.
Should i use Popover
or not as per the apple documentation?Since its working fine in iphone,will my app get rejected for using it later?