Ios swift 3.0中的汉德尔在哪里
我想在背压时刷新整个页面控制器。 我正在使用代码导航viewcontroller 我的代码Ios swift 3.0中的汉德尔在哪里,ios,swift,swift3,Ios,Swift,Swift3,我想在背压时刷新整个页面控制器。 我正在使用代码导航viewcontroller 我的代码 let GTC = self.storyboard?.instantiateViewController(withIdentifier: "GoToCart")as! GoToCart self.navigationController?.pushViewController(GTC, animated: true) 使用view将显示以重新加载您的UI。使用navigationController?.
let GTC = self.storyboard?.instantiateViewController(withIdentifier: "GoToCart")as! GoToCart
self.navigationController?.pushViewController(GTC, animated: true)
使用
view将显示
以重新加载您的UI。使用navigationController?.pushViewController
时,视图将保留并存储在堆栈中
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Reload the UI
}
视图将出现
在第一次显示视图以及再次显示视图时被调用,因此在视图控制器对象的生命周期内可以多次调用。当用户点击“上一步”按钮导致视图即将显示时,当在选项卡栏控制器中选择视图控制器的选项卡时,会调用该函数。请确保在实现过程中的某个时刻调用super.viewWillExample()
。您可以使用此方法刷新UI
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Reload the UI
}
更好的方法是使用协议
class MainViewController:UIViewController,GoCartControllerDelegate
{
// Define Delegate Method
func childViewControllerResponse(parameter)
{
//...here update what you want to update according to the situation
}
}
protocol GoCartControllerDelegate
{
func childViewControllerResponse(parameter)
}
class GoToCart:UIViewController
{
var delegate: ChildViewControllerDelegate?
....
}
然后在mainViewController中实现协议功能,最终扩展到协议
class MainViewController:UIViewController,GoCartControllerDelegate
{
// Define Delegate Method
func childViewControllerResponse(parameter)
{
//...here update what you want to update according to the situation
}
}
2重要的事情
当导航到gocart控制器代码时,如下所示
let GTC = self.storyboard?.instantiateViewController(withIdentifier: "GoToCart")as! GoToCart
GTC.delegate = self
self.navigationController?.pushViewController(GTC, animated: true)
self.navigationController?.popViewController(animated:true)
self.delegate?.childViewControllerResponse(parameter)
当从gocartViewController弹出时
代码是这样的
let GTC = self.storyboard?.instantiateViewController(withIdentifier: "GoToCart")as! GoToCart
GTC.delegate = self
self.navigationController?.pushViewController(GTC, animated: true)
self.navigationController?.popViewController(animated:true)
self.delegate?.childViewControllerResponse(parameter)