Premox
Premox

Reputation: 343

How to enable the UIButton?

I have two viewcontrollers 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

Answers (3)

Sanket_B
Sanket_B

Reputation: 745

Change flag in both, viewDidLoad and viewWillAppear

Upvotes: -3

tmac_balla
tmac_balla

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

pradip kikani
pradip kikani

Reputation: 637

  .userInteractionEnabled = true;     
  [self dismissViewControllerAnimated:YES completion:nil];

please try it. This code writes when you close or dismiss second view.

Upvotes: 0

Related Questions