我想从VC1(所有餐厅视图)导航到VC2(餐厅详细信息视图),当我按“后退按钮”时,它不应该再重新加载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
最佳答案
按下后退按钮后,可以使用块执行任何操作。遵循以下代码
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)
关于swift - 从CV2单击时不要重新加载VC1-Swift,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54215641/