Reputation: 343
I have two viewcontroller
s in a storyboard. The first view is the LaunchScreen
, which appears first. With UILongPressGestureRecognizer
the second View will be displayed.
The first time the second view is displayed my code of the second view is checking a flag if a file exists. The second view has a UIButton
which is disabled if the file doesn't exist. If I close the second view with
[self dismissViewControllerAnimated:YES completion:nil];
the second view disappears and I see my first view. It works well.
But if I repeat it and the second view appears, the viewcontroller
doesn't check the flag I changed, because the file exists now.
The following method
-(void)showConfigView {
[self presentViewController:[self config] animated:YES completion:nil];
}
is calling the second View.
My question is: Why is my UIButton
still disabled although the flag has another value and the file exist ?
Upvotes: 1
Views: 165
Reputation: 648
What you need to do is to check the flag each time the view controller is closed or shown. You can do it in showConfigView
before calling presentViewController
or before dismissViewControllerAnimated
if it is what you are using.
But the best practice is to check conditions in viewWillAppear
or in viewDidLoad
.
To enable the button you write
.userInteractionEnabled = true;
Upvotes: 4
Reputation: 637
.userInteractionEnabled = true;
[self dismissViewControllerAnimated:YES completion:nil];
please try it. This code writes when you close or dismiss second view.
Upvotes: 0