Ios n添加弹出窗口时出现InternalInconsistencyException

Ios n添加弹出窗口时出现InternalInconsistencyException,ios,swift,Ios,Swift,我想在swift中创建一个弹出窗口,并在用户单击按钮时显示它。 我不使用故事板,视图是通过编程创建的 class CreateNoticePopupViewController: UIViewController { var popUpView = UIView() let titleTextField: UITextField = { let title = UITextField() title.placeholder = "Enter Title" title.

我想在swift中创建一个弹出窗口,并在用户单击按钮时显示它。 我不使用故事板,视图是通过编程创建的

class CreateNoticePopupViewController: UIViewController {

var popUpView = UIView()

let titleTextField: UITextField = {
    let title = UITextField()
    title.placeholder = "Enter Title"
    title.translatesAutoresizingMaskIntoConstraints = false;
    title.font = UIFont.boldSystemFont(ofSize: 24)
    return title
}()

let descriptionTextView: UITextView = {
    let description = UITextView()
    description.translatesAutoresizingMaskIntoConstraints = false;
    description.font = UIFont.boldSystemFont(ofSize: 24)
    description.isUserInteractionEnabled = true
    return description
}()

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
    self.popUpView.layer.cornerRadius = 5
    self.popUpView.layer.shadowOpacity = 0.8
    self.popUpView.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
}

func showInView(aView: UIView!, animated: Bool)
{
    self.view.addSubview(titleTextField)
    self.view.addSubview(descriptionTextView)
    aView.addSubview(self.view)

    self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]|", options: NSLayoutFormatOptions(),
                                                  metrics: nil, views: ["v0": titleTextField]))

    self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]|", options: NSLayoutFormatOptions(),
                                                  metrics: nil, views: ["v0": descriptionTextView]))

    self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-4-[v0]-4-[v1]-4-|", options: NSLayoutFormatOptions(),
                                                  metrics: nil, views: ["v0": titleTextField, "v1": descriptionTextView]))

    if animated
    {
        self.showAnimate()
    }
}

func showAnimate()
{
    self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
    self.view.alpha = 0.0;
    UIView.animate(withDuration: 0.25, animations: {
        self.view.alpha = 1.0
        self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
    });
}

func removeAnimate()
{
    UIView.animate(withDuration: 0.25, animations: {
        self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
        self.view.alpha = 0.0;
    }, completion:{(finished : Bool)  in
        if (finished)
        {
            self.view.removeFromSuperview()
        }
    });
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
}
通过按钮,我将其称为视图控制器,如下所示:

let popViewController = CreateNoticePopupViewController(nibName: "PopUpViewController", bundle: nil)
popViewController.showInView(aView: self.view, animated: true)
然后它给了我这个错误。我正在关注这个链接

这就是我犯的错误
“NSInternalInconsistencyException”,原因:“无法在捆绑包中加载NIB:”名为“PopUpViewController”的NSBundle

如果VC是以编程方式创建的,则不加载此捆绑包

let popViewController = CreateNoticePopupViewController(nibName: "PopUpViewController", bundle: nil)


谢谢,现在可以用了。。我已经接受并投票支持你的答案,虽然两个答案都不会被反映出来。你现在不能投票,因为这取决于代表的数量,6分钟后检查,它会反映出来
let popViewController = CreateNoticePopupViewController()