How can I determine if my view manager is visible and receiving events?

I have a view that I will say in order to update its data. But sometimes the data changes when the view is not displayed. So, how can I detect that the viewcontroller is visible and receiving events? I could add a boolean that was changed in viewWillAppear and viewWillDisappear, but there seems to be a way to directly detect the state ...

Thanks Gary

+3
source share
3 answers

Short answer: if you use the UINavigationController, you can use its visibleViewController so that you do not have to track a single boolean value.

: , , reloadData viewWillAppear, , . reloadData , . . , , , , , , . , ... , - ...

+12

- :

[(UITableView *)[self view] reloadData];

viewControllerWillAppear. , , .

+1

You can probably check the property of the viewport:

- (BOOL)isVisible
{
  return view.window != NULL;
}

But I think maintaining a variable is BOOLbetter.

0
source

Source: https://habr.com/ru/post/1708141/


All Articles