Is it safe to dismiss a viewController without closing the document Object

174 Views Asked by At

My application is a document based application I present the saved content using an UIViewController subclass EditViewsController with the help of my customized UIDocument object.

EditViewsController will look like below

enter image description here

Tapping the close Button on the left top corner will fire the below method

-(IBAction)closeForm:(id)sender
{
        // _formDocument is my UIdocument subclass Object
        [_formDocument closeWithCompletionHandler:^(BOOL completion){
                [self dismissViewControllerAnimated:YES completion:nil];
         }];
}

My problem is that while calling the method closeWithCompletionHandler my application freezes for a while before closing.

My question is that is it right to dismiss the viewcontroller without closing the document (simply call dismissViewControllerAnimated: inside the firing method) or I have to run that method in background thread to get rid of freezing?

1

There are 1 best solutions below

14
On
-(IBAction)closeForm:(id)sender
{
    // _formDocument is my UIdocument subclass Object
    [_formDocument closeWithCompletionHandler:^(BOOL completion){
            [NSOperationQueue mainQueue] addOperationBlock:^{
                 // Dismissing it on main thread
                 [self dismissViewControllerAnimated:YES completion:nil];
            }];
     }];
}