我想从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
答案 0 :(得分:1)
按下后退按钮后,您可以使用块执行任何操作。请遵循以下代码
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)
答案 1 :(得分:0)
如果您在VC1中使用UITableView
,然后在viewWillAppear
中重新加载它,那么您将得到更新,或者这是刷新列表的原因
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.tableview.reloadData()
}
答案 2 :(得分:0)
请在VC1类的viewWillAppear
方法中编写以下代码:
self.view.setNeedsDisplay()
这可能会对您有所帮助。谢谢