从 CV2 单击返回时不要重新加载 VC1 - Swift

Don't reload VC1 when clicking back from CV2 - Swift

我想从 VC1(所有餐厅视图)导航到 VC2(餐厅详细信息视图),当我按下 "Back Button" 时,它不应再次重新加载 VC1。

我该如何解决这个问题?

func clickNameButtonCollectionView(sender: UIButton) {

        let restaurent_Id = ((self.allRecommendedRestaurent[sender.tag]  as AnyObject).value(forKey: "id") as AnyObject) as? Int

        let obj = self.storyboard?.instantiateViewController(withIdentifier: "ResturantDetailsController") as! ResturantDetailsController
        obj.restaurent_ID = restaurent_Id!
        self.navigationController?.pushViewController(obj, animated: true)
    }


@IBAction func backPressed(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }

已添加:

override func viewDidLoad() {
        super.viewDidLoad()

        self.refreshControl.addTarget(self, action: #selector(self.reloadJoinedData), for: UIControlEvents.valueChanged)
        self.mainScrollView?.addSubview(refreshControl)

        self.appDel.apiManager.setCurrentViewController(vc: self)

        // Do any additional setup after loading the view.

        resturantTable.delegate = self
        resturantTable.dataSource = self
        resturantTable.bounces = false
        resturantcollection.delegate = self
        resturantcollection.dataSource = self
        resturantcollection.bounces = false

如果您在 VC1 中使用 UITableView,然后在 viewWillAppear 中重新加载它,那么您将得到更新或者这是您刷新列表

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)

    self.tableview.reloadData() 

}

请将这段代码写在VC1的viewWillAppear方法中class:

 self.view.setNeedsDisplay()

它可能会帮助 you.Thank 你。

您可以使用块在按下后退按钮后执行任何操作。按照下面的代码

1) 在您的 ResturantDetailsController

中创建块
var back_block : (() -> Void)? = nil

2) 更新您的后退按钮操作 backPressed

@IBAction func backPressed(_ sender: Any) {
    if let action = back_block {
        action()
    }
    self.navigationController?.popViewController(animated: true)
}

3) 现在在 VC1 中创建 ResturantDetailsController 对象。

    let obj = ResturantDetailsController.loadController()
    obj.back_block = {
        //reload Your TableView
    }
    obj.restaurent_ID = restaurent_Id!
    self.navigationController?.pushViewController(obj, animated: true)