I have a master view (UITableView) with two properties that I want to be set only the first time the view is shown (that is; only when the application starts), but not when the view is shown again later on runtime (eg when a push-segue drags it on again etc.)
How is this possible? Maybe there's something I've missed?
Thanks in advance. All help is greatly appreciated.
You may use dispatch_once
in a corresponding view controller's method viewDidAppear:
:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
static dispatch_once_t once;
dispatch_once(&once, ^{
... your code to be executed only once ...
});
}
Set it in the init
method of the class.
Then, if the class is shown again, viewWillAppear
will be called, so you can set the property back to the value you want.
Another option is to play with the methods viewDidLoad
and viewDidAppear
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.