Supratik Majumdar
Supratik Majumdar

Reputation: 2466

Operations After UIAlert is dismissed causes dealays

I am currently making a registration form for my App. Once the user hits the register button a alert is given to the user to to confirm the number and proceed.

Screenshot of Alert:

enter image description here

If the user hits cancel I perform the following operations:

/*** Reset Mobile Number Input ***/
                        self.flagMobileNumber = 0
                        self.validatorIconMobileNumber.setImage(nil, forState: UIControlState.Normal)
                        self.mobileNumberInput.text = ""
                        self.mobileNumberInput.becomeFirstResponder()

                    /*** Disable Register Button ***/
                        self.registerButton.alpha = 0.5
                        self.registerButton.userInteractionEnabled = false

But there is a considerable delay that occurs before all the operations are completed.

May someone explain why this happens and what can be done to prevent it.

Upvotes: 0

Views: 51

Answers (1)

Eli Waxman
Eli Waxman

Reputation: 2897

You are probably aren't on the main thread, doing UI stuff on a different thread (other than the main thread) is discouraged, and usually takes time.

try doing your UI stuff on the main thread:

dispatch_async(dispatch_get_main_queue(), ^{
// do UI stuff here
});

Upvotes: 1

Related Questions