Don't reload VC1 when clicking back from CV2 -

2019-08-31 03:54发布

I would like to navigate from VC1 (All Restaurant View) to VC2 (Restaurant Details View) and when ill press "Back Button" it shouldn't reload VC1 again.

How can I solve this?

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)
    }

Added:

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

3条回答
Ridiculous、
2楼-- · 2019-08-31 04:29

You can use block to perform any action after back button press. Follow below code

1) Create block in your ResturantDetailsController

var back_block : (() -> Void)? = nil

2) Update your back button action backPressed

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

3) Now in VC1 when you create ResturantDetailsController object.

    let obj = ResturantDetailsController.loadController()
    obj.back_block = {
        //reload Your TableView
    }
    obj.restaurent_ID = restaurent_Id!
    self.navigationController?.pushViewController(obj, animated: true) 
查看更多
相关推荐>>
3楼-- · 2019-08-31 04:33

Please write this code in viewWillAppear method in VC1 class:

 self.view.setNeedsDisplay()

It may helps you.Thank you.

查看更多
我想做一个坏孩纸
4楼-- · 2019-08-31 04:38

If you are using UITableView in VC1 then reload it in viewWillAppear then you will get updated or this is you refresh your list

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

    self.tableview.reloadData() 

}
查看更多
登录 后发表回答