好的,我这里有2个问题:
1 我尝试从xib文件中的按钮加载ViewController。 这是我的xib按钮:UIView。
<rule name="Change Location Header" enabled="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^http(s)?://([^/]+)/(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{RESPONSE_STATUS}" pattern="^301" />
<add input="{RESPONSE_STATUS}" pattern="^302" />
</conditions>
<action type="Rewrite" value="http{R:1}://{R:2}/{R:3}" />
</rule>
这里的问题是@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)
}
,因为我的xib是一个UIView类型,他告诉我这个错误:&#34;(值类型ViewController)没有presentViewController&#34;的成员。
为什么我尝试使用此代码?是因为在我的CalendarioViewController中按下按钮时我有这个代码:presentViewController
所以这是我的第一个问题......
2
第二个问题是当我在我的xib中的一个按钮中有这个代码时:UIView,CalendarioViewController加载正常......但代码:dismiss(animated: true, completion: nil)
不再工作了。
这是我的按钮xib的代码:
dismiss(animated: true, completion: nil)
So..how可以加载一个ViewController(CalendarioViewController)和解雇代码Keep运行吗?
答案 0 :(得分:0)
在override func viewDidLoad()
中输入此代码:
let fechaArriboTap = UITapGestureRecognizer(target: self, action:#selector(handleArribo))
let fechaSalidaTap = UITapGestureRecognizer(target: self, action:#selector(handleSalida))
fechaArribo.addGestureRecognizer(fechaArriboTap)
fechaSalida.addGestureRecognizer(fechaSalidaTap)
然后创建方法:
func handleArribo() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc:CalendarioViewController = storyboard.instantiateViewController(withIdentifier: "calendario") as! CalendarioViewController
vc.dateDelegate = self
present(vc, animated: true, completion: nil)
}
func handleSalida() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc:CalendarioViewController = storyboard.instantiateViewController(withIdentifier: "calendario") as! CalendarioViewController
vc.dateDelegate = self
present(vc, animated: true, completion: nil)
}
那就是!谢谢@sasquatch