Reload UITableView when navigating back?

前端 未结 7 1675
醉梦人生
醉梦人生 2021-01-30 06:38

I have a top level UIViewController that contains a UITableView. The top level UIViewController instantiates a NavigationController

7条回答
  •  深忆病人
    2021-01-30 07:07

    viewWillAppear gets called every time the view appears include the first time. Here is my solution for reload the view only when you navigate back

    I create one variable in .h file of my ViewController for checking that it is the first time I go to this ViewController or when I navigate back

    @property (nonatomic) BOOL isViewExist;
    

    After that in viewWillAppear

    -(void)viewWillAppear:(BOOL)animated{
        if(!self.isViewExist){
            self.isViewExist = YES; // check it is the first time you go to this ViewController -> don't reload anything
        }else{
            [self.tableView reloadData]; // to reload the tableview data
            // or your can refresh anything in your ViewController as you want
        }
    }
    

    Hope this help

提交回复
热议问题