【发布时间】:2017-12-09 17:04:39
【问题描述】:
好的,我这里有两个问题:
1 我尝试从 xib 文件中的按钮加载 ViewController。 这是我的 xib 中的按钮:UIView。
@IBAction func fechaSalida(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "calendario") as! CalendarioViewController
self.presentViewController(vc, animated: true, completion: nil)
}
这里的问题是presentViewController,因为我的 xib 是 UIView 类型,他告诉我这个错误:“(value type ViewController) has no member of presentViewController”。
为什么我尝试使用此代码?是因为在我的 CalendarioViewController 中按下按钮时我有这个代码:dismiss(animated: true, completion: nil) 所以这是我的第一个问题......
2
第二个问题是当我在 xib 内的按钮中有此代码时:UIView,CalendarioViewController 加载正常...但代码:dismiss(animated: true, completion: nil) 不再工作。
这是我的按钮 xib 的代码:
@IBAction func fechaSalida(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc:CalendarioViewController = storyboard.instantiateViewController(withIdentifier: "calendario") as! CalendarioViewController
vc.dateDelegate = self
self.window!.rootViewController = vc
}
那么..如何加载 ViewController (CalendarioViewController) 和关闭代码保持运行?
【问题讨论】:
-
找到UIView的父VC,对VC执行动作
-
对不起...我无法关注你...
-
视图无法呈现视图控件。所以你必须找到持有该视图的视图控制器,然后从该父视图控制器中呈现另一个视图控制器
-
啊...好吧,现在我明白了...我会尝试的!谢谢!
-
我认为诀窍是如何从 rootViewController 中解散...此代码不起作用:self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)跨度>
标签: swift xib viewcontroller