我正在尝试在触摸按钮时显示我在屏幕上的xib中创建的视图。我希望它以屏幕中间的表单样式显示。然而,在这一点上,我一直试图让它显示出来,然后再担心这个位置。
我为它分配并创建了“CallNowView”类,现在看起来就是这样。
import Foundation
import UIKit
class CallNowView: UIViewController{
@IBOutlet var btnCancel: UIButton!
@IBOutlet var btnCall: UIButton!
@IBAction func btnCall_pressed(_ sender: AnyObject) {
}
@IBAction func btnCancel_pressed(_ sender: AnyObject) {
}
}
我想在xib显示的视图中尝试做的是以下
@IBAction func btnRSRCall_pressed(_ sender: AnyObject) {
if (callNowView == nil)
{
callNowView = CallNowView(nibName: "CallNow", bundle: nil)
}
if(UIViewController.responds(to: #selector(getter: popoverPresentationController))){
callNowView.modalPresentationStyle = .formSheet
callNowView.popoverPresentationController?.sourceView = btnCall;
callNowView.popoverPresentationController?.sourceRect = btnCall.bounds;
callNowView.popoverPresentationController?.permittedArrowDirections = .any
}
else {
//no support ios7 device, either ipad or iphone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone)
{
//present standard controller for ios7, iphone,
self.present(callNowView, animated: true, completion: nil)
}
else
{
//present s popupcontroller for ios7, ipad
let popover = UIPopoverController.init(contentViewController: callNowView)
popover.present(from: btnCall.bounds, in: btnCall, permittedArrowDirections: .any, animated: true)
}
}
}
当我运行代码时,它会在此行self.present(callNowView, animated: true, completion: nil)
上崩溃并显示错误terminating with uncaught exception of type NSException
我希望有人可以帮我解决这个问题