当我单击后退按钮时,我需要更新我的viewPagerController。主视图中的我的视图分页器控制器。我在主视图上使用容器视图。我需要重新加载并更新我的viewpagercontroller.when,当我单击后退按钮时,我的主视图containerview需要update.my容器视图包含viewpagercontroller。 我正打算删除Viewpager页面。但是,当我使用后退按钮发送数据并删除Viewpager控制器页面变量数据时,协议无法正常工作。请为viewpagercontroller视图删除提供帮助。
@IBAction func backBtn(_ sender: Any) {
let vc = storyboard?.instantiateViewController(withIdentifier: "main") as! ViewController
self.navigationController?.popToRootViewController(animated: true)
}
//viewpagecontroller code
class PageViewController: UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
var deleteVCIndex:Int!
let locationManager = CLLocationManager()
let apiKey = "2498ab54f99be8656cc0bea1f57434ed"
var lat:Double = 27.34
var lon:Double = 104.33
var activityIndicator: NVActivityIndicatorView!
var textLabel = UILabel()
/// total viewpager page array
lazy var VCArr: [UIViewController] = Utility.shareInstance.VCArr
/// uipageControl
var pageControl = UIPageControl()
var pagecount = 0
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = VCArr.firstIndex(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex - 1
guard nextIndex > -1 else {
return nil
}
guard VCArr.count > nextIndex else {
return nil
}
return VCArr[nextIndex]
}
//pageviewcontroller after paging func
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = VCArr.firstIndex(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
guard nextIndex < VCArr.count else {
return nil
}
guard VCArr.count > nextIndex else {
return nil
}
return VCArr[nextIndex]
}
当我单击按钮时,我进入主视图。并且主视图包含viewpagercontroller,我需要在viewpagercontroller上删除页面。 给我一些建议..谢谢