When I first call following code from dispatch queue, completion block not called.
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_queue_t initialize_queue;
initialize_queue = dispatch_queue_create("init", NULL);
dispatch_async(initialize_queue, ^{
_onInit = YES;
_isRunning = NO;
[self startProgress];
_onInit = NO;
});
}
- (void)startProgress
{
if (!_isRunning) {
_isRunning = YES;
NSLog(@"Starting");
[UIView animateWithDuration:0.5 animations:^{
self.progressStatusButton.hidden = NO;
self.activityLeftConstraint.constant = _activityLeftSpace;
self.activityWidthConstraint.constant = _activityWidth;
self.buttonWidthConstraint.constant = _progressStatusButtonWidth;
self.buttonLeftConstraint.constant = _progressStatusButtonLeftSpace;
self.activityView.alpha = 1.0;
}completion:^(BOOL finished){
NSLog(@"Start Animating");
[self.activityView startAnimating];
}];
}
}
When I delete dispatch_aync
method and execute startProgress
method in viewDidLoad
,
completion block called. How should I correct my code?
I tried to change dispatch_async
to use dispatch_async(dispatch_get_main_queue(),..)
,
then completion block called, but I would like to execute asynchronously startProgress
method.
Please Let me know.