【发布时间】:2015-02-02 13:01:44
【问题描述】:
我正在尝试制作一个弹出窗口,就像我在 previous question 中描述的那样。我实际上得到了答案,但现在我有一个新问题。如果我不制作instantiateWithOwner,我可以让视图出现,但它没有响应任何东西(只是冻结)。
简而言之,我建立了一个“popup.xib”文件,它只是一个带有按钮和标签的视图。我下面的代码应该让它随着按钮的点击而出现和消失。
我已经阅读了 instantiateWithOwner 将视图连接到它的回调按钮的所有魔法的文档,因此当它不在代码中时没有任何事情发生是有道理的。 (reference)
问题是,如果我将它包含在我的代码中,我会收到编译器错误'PopupViewConrtoller' does not have a member named 'instantiateWithOwner'。
我尝试搜索自动完成列表,但没有找到类似的东西。
我的代码:
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBAction func showPopup(sender: AnyObject) {
// This line makes it appear on the screen, but not respond to anything.
var x = PickerPopupViewConrtoller(nibName: "PickerPopup", bundle: nil)
// This line does not compile.
var x = PickerPopupViewConrtoller(nibName: "PickerPopup", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as? PickerPopupViewConrtoller
x.show(self.view)
}
}
PopupViewController
import UIKit
class PickerPopupViewConrtoller : UIViewController {
func show(tView : UIView) {
tView.addSubview(self.view)
}
@IBAction func done(sender: AnyObject) {
self.view.removeFromSuperview()
}
}
【问题讨论】:
标签: ios xcode swift ios8 xcode6